Editor

Predict the Output

Beginner · Predict the output · from Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

From the lesson: Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

Every day you make hundreds of decisions. If it's raining, you grab an umbrella. If the traffic light is red, you stop. If your phone battery is below 20%, you look for a charger. These are all conditional decisions - you check something and act based on the result.

Read the lesson

Without running the code, predict what it will print. Then run it to check.

Think carefully about which conditions are True and which are False.

x = 15
if x > 20:
print('A')
elif x > 10:
print('B')
elif x > 5:
print('C')
else:
print('D')
print('Done')

More if else exercises

All Python exercises · 50 practice problems · Control Flow quiz