🐸

Plan B

Python Basicspython-basics-11-plan-b
Reward: 80 XP
|

Plan B

Sometimes things don't go as planned. What if the door is locked? You need a backup plan.

In Python, else tells the computer what to do if the if condition is False.

The Else Spell

is_door_open = False

if is_door_open:
  print("Walk through door")
else:
  print("Climb through window")

Think of it as: "If this is true, do this. Otherwise, do that."

Your Mission

1
The Situation

Create a variable is_sunny and set it to False.

2
The Plan

Write an if statement checking is_sunny.

3
Sunny Day

Inside the if block, print "Play outside".

4
Rainy Day

Add an else block and print "Stay inside".

Formatting

The else keyword must line up with the if keyword. Don't indent the else itself, but indent the code inside it!

Suggested Solution
Click to expand

Here is your backup plan:

is_sunny = False

if is_sunny:
  print("Play outside")
else:
  print("Stay inside")
Advanced Tips
Want more? Click to expand

You can use not to check for the opposite!

is_raining = True
if not is_raining:
  print("Go outside")
else:
  print("Bring umbrella")
pymain.py
Loading...
Terminal
Terminal
Ready to run...