← back to unit
Medium
# basics conditionals
Nested if Statements
You can put an if inside another if — this is called nesting. The inner one only gets checked at all if the outer one is True:
if has_ticket == 1:
if age >= 13:
print("Enjoy the movie!")
else:
print("This movie is rated PG-13.")
else:
print("Please buy a ticket first.")
Your turn: read has_ticket (1/0) and age. If has_ticket is 1: print Enjoy the movie! when age >= 13, otherwise print This movie is rated PG-13.. If has_ticket is 0, print Please buy a ticket first.
💡 need a hint?
pyb-cond-nested.py🔒 given lines are locked — write your code in between
loading...