Posts

Showing posts with the label Nested Conditional Statements

Nested Conditional Statements

Image
  Nested Conditional Statements Nested Conditions The conditional block inside another if/else conditional block is called as nested conditional block . In the below example, Block 2 is nested conditional block and condition B is called nested conditional statement. Code 1 2 3 4 5 6 matches_won = int ( input ( )) goals = int ( input ( )) if matches_won > 8 : if goals > 20 : print ( "Hurray" ) print ( "Winner" ) PYTHON Input 10 22 Output Hurray Winner Input 10 18 Output Winner Nested Condition in Else Block We can also write nested conditions in Else Statement. In the below example Block 2 is a nested conditional block. Code 1 2 3 4 5 6 7 8 9 10 11 a = 2 b = 3 c = 1 is_a_greatest = ( a > b ) and ( a > c ) if is_a_greatest : print ( a ) else : is_b_greatest = ( b > c ) if is_b_greatest : print ( b ) else :   PYTHON Expand Output 3 Elif Statement Use the elif statement to have multi...