python · level 1 · unit 4 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
An if runs code only when its is True.
Picture a fork in the path with a sign: Is it Saturday? An if asks a condition like that. If the answer is yes, Python takes the path and runs the lines inside. If not, it walks straight past.
Python answers every condition with True or False. A value that can only be one of these two is a . To ask whether two values match, use two equals signs, ==. One = puts a value in a box.
The if line ends with a colon. The lines inside start with four spaces. That tells Python which lines belong to the if.
day = "Saturday"
print(day == "Saturday")
if day == "Saturday":
print("Pancakes for breakfast!")
print("Time to get dressed.") Lines without indentation sit outside the if, so they run every time.
guess first
Rain or shine? Guess what this shows.
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
weather = "sunny"
if weather == "rainy":
print("Take a coat.")
print("Off you go!")
your turn
Your turn. Get past the robot door.
The robot only opens for its owner. Type your name in both boxes, spelled exactly the same, then press run.
fix it
The quiz has crashed. Can you fix it?
- Python stopped at the
ifline. Look at the sign betweenanswerand"Paris". - One
=puts a value in a box. To ask whether two values match, you need two. - Change
=to==on line 2, then press run.
nailed it
your code can make choices now. :D
ifruns its indented lines only when the condition isTrue.- Use
==to ask whether two values match. - End the
ifline with a colon, then indent.
new words in your collection
- condition
- boolean
- indentation
This lesson isn’t saved. A free account remembers every lesson you finish.