1) What do I need to do?
π― Your mission: Bug hunt: the secret door
This code has 3 bugs. Fix them so it prints Access granted.
2) What do I need to know?
if: do it only when it's True
if checks a question. If it's True, Python runs the lines underneath.
The if line ends with a colon : and the lines inside are pushed in with 4 spaces. This is called indenting.
π§° Your toolkit for this mission
Everything you need to know to finish this lesson on your own:
if
Run some code only when a question is True.
How to write it: Write if question: β don't forget the colon β then indent (4 spaces) the lines underneath.
if score >= 90:
print("Legend")elif
"Else if" β another question to try if the ones before were False.
How to write it: Same line up as if, with its own question and colon.
elif score >= 50:
print("Hero")else
"Otherwise" β runs when none of the questions were True.
How to write it: else: has no question, just a colon.
else:
print("Sidekick")Order matters
Python checks top to bottom and stops at the first True one.
How to write it: Put the hardest test first (90 before 50).
Comparing text
Check what the player typed.
How to write it: Use == and quotes: if weather == "sunny":. Spelling and capitals must match exactly.
weather = input("Weather? ")
if weather == "sunny":
print("Solar power!")Think about it
Look at this code. What happens next, and why? Say it in your own words.
if True:
print("Fly!")
print("Done")Watch & explore βΆ
Power-up: if: do it only when it's True
See it happen
1 / 3power = 80
if power > 50:
print("Fly!")If the check is True, run the indented line.
3) Run the code & terminal output
Press βΆ RUN and your program's messages appear here!


Captain Py
Our next adventure is yours to create.
