Tutorial 5/15 Making Decisions

Python: Conditionals

Teach your program how to make choices using if and else.

The Hook

The IF Statement is like a Club Bouncer.

  • It checks your ID (the Condition).
  • IF Condition is True -> "Come in!"
  • ELSE (Otherwise) -> "Go home!"
Access Protocol

Colons & Indents

Notice the colon (:) and the indentation (tab/4 spaces).

password = input("PIN: ")
# Get input
if password == "1234":
# Note the COLON :
print("Welcome")
# Indented!
else:
# Otherwise...
print("Locked")
# Runs if False
Logic Hub

Predict

If age is 15, what will be printed?

if age >= 18:
  print("Vote")
else:
  print("Wait")

Live Python Lab

If / Else Decision Logic.

> SYSTEM READY_
> _
BRONZE

🥉 New High Score

Change the Threshold from 50 to 90. It should print "Failed".

> _
SILVER

🥈 Missing Colon

The code below is broken because of a missing Colon (:). Fix it!

> _
GOLD

🥇 Password Protection

Ask for a PIN. If it is "1234" print "Unlock", otherwise print "Locked".

> _