CBSE Class 11 Informatics Practices Question 52 of 75

Conditional and Looping Constructs — Question 24

Back to all questions
24
Question

Question 8

Write the output of the following program on execution if x = 50:

if x > 10:
   if x > 25:
      print ( 'ok' )
      if x > 60:
           print ( 'good' )
      elif x > 40:
           print ( 'average' )
      else:
           print ('no output')
Answer
Output
ok
average
Explanation
  1. if x > 10:

    • The condition checks if x is greater than 10.
    • Since x = 50, which is greater than 10, this condition is true.
  2. Nested if x > 25:

    • Since the outer condition is true, the program proceeds to this nested condition, which checks if x is greater than 25.
    • Since x = 50, which is greater than 25, this condition is also true.
    • Consequently, it prints ok
  3. Nested if x > 60:

    • After printing 'ok', the program checks this nested condition, which verifies if x is greater than 60.
    • Since x = 50, which is not greater than 60, this condition is false.
    • Therefore, the program proceeds to the elif part.
  4. Nested elif x > 40:

    • This condition checks if x is greater than 40.
    • Since x = 50, which is greater than 40, this condition is true.
    • Consequently, it prints average
  5. The else block

    • The else block is not executed because the elif x > 40: condition was true.