Skip to content

Question 10

What is the output of the following code?

x = 30
if x < 100:
    if x > 50:
        print('A')
    elif x > 10:
        print('B')
    else:
        print('C')
else:
    print('D')
Solution

Given x = 30,

  • x < 100 is True, enter if block.
  • x > 50 is False, skip to subsequent elif block.
  • x > 10 is True, enter elif block.
  • Print out 'B'.
Answer
'B'