Back to articles
Ternary Operator, GCD, Prime Numbers

Ternary Operator, GCD, Prime Numbers

via Dev.to PythonSasireka

1)Ternary Operator A ternary operator is a shorthand conditional operator ( condition ? exprIfTrue : exprIfFalse) that evaluates a condition and returns one of two values based on whether the result is true or false, acting as a concise replacement for simple if-else statements. Python a = 10 b = 5 c = 8 smallest = a if ( a < b and a < c ) else ( b if b < c else c ) print ( " Smallest number is: " , smallest ) Output Javascript let a = 100 ; let b = 55 ; let c = 67 ; let smallest = ( a < b && a < c ) ? a : ( b < c ? b : c ); console . log ( " Smallest number is: " , smallest ); Output Java public class SmallestOfThree { public static void main ( String [] args ) { int a = 55 ; int b = 99 ; int c = 32 ; int smallest = ( a < b && a < c ) ? a : ( b < c ? b : c ); System . out . println ( "Smallest number is: " + smallest ); } } Output 2)Range of Prime Number Flowchart Python no1 = 10 while no1 <= 50 : div = 2 flag = True while div <= no1 // 2 : if no1 % div == 0 : flag = False break div =

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
6 views

Related Articles