is_raining = False
if is_raining:
print("Take an umbrella")
else:
print("Enjoy the sun")Line-by-line explanation
- The first line stores False.
- The if condition checks that value.
- Its indented line is skipped.
elseprovides the other path.- The final message is displayed.
score = 70
if score >= 90:
print("Gold")
elif score >= 60:
print("Silver")
else:
print("Bronze")Line-by-line explanation
- The score is stored.
- The first condition is False.
- The elif condition is True, so Silver is displayed.
- Python skips the remaining else block.
Tiny Practice
Display “Open” when is_open is True and “Closed” otherwise.
Starter template
is_open = False
if is_open:
print("Open")
CHANGE_MELine-by-line explanation
- The if path is complete.
- You need the otherwise path.
Hint
- Use
else. - Add a colon.
- Indent the Closed message.
Show Solution
is_open = False
if is_open:
print("Open")
else:
print("Closed")Line-by-line explanation
- False skips the first message.
- The else path runs.
- The output is
Closed.