Informatics Practices
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
ok
average
Working
if x > 10:
- The condition checks if
xis greater than 10. - Since
x = 50, which is greater than 10, this condition is true.
- Nested
if x > 25:
- Since the outer condition is true, the program proceeds to this nested condition, which checks if
xis greater than 25. - Since
x = 50, which is greater than 25, this condition is also true. - Consequently, it prints
ok
- Nested
if x > 60:
- After printing 'ok', the program checks this nested condition, which verifies if
xis greater than 60. - Since
x = 50, which is not greater than 60, this condition is false. - Therefore, the program proceeds to the
elifpart.
- Nested
elif x > 40:
- This condition checks if
xis greater than 40. - Since
x = 50, which is greater than 40, this condition is true. - Consequently, it prints
average
- The
elseblock
- The
elseblock is not executed because theelif x > 40:condition was true.
Related Questions
Write the output of the following:
for x in range (10, 20): if (x == 15): break print(x)Write the output of the following:
for x in range (10, 20): if (x % 2 == 0): continue print (x)Write the output of the following code:
for i in range (2) : for j in range (1) : if i+2 == j: print ("+",end=" ") else: print ("o",end=" ")WAP to display even numbers between 10 and 20.