and, or, not
Sometimes one condition isn’t enough. “If you’re older than 13 and you have a ticket — come in.” Python has three keywords for exactly this:
| Word | Meaning | It’s true when… |
|---|---|---|
and | and | both conditions are true |
or | or | at least one is true |
not | not | the opposite of the condition is true |
and — both are required
Section titled “and — both are required”Inputs (for input())
One value per line — read in order by input().
Write ticket = "no" and run it again — when and doesn’t see both sides as true, the whole condition becomes false.
or — one is enough
Section titled “or — one is enough”Inputs (for input())
One value per line — read in order by input().
not — flip it around
Section titled “not — flip it around”Inputs (for input())
One value per line — read in order by input().
not False becomes True, which is why the warning was printed. Try writing True and see.
Missions
Section titled “Missions”Ride entry
+10 XP ✓ CompletedRide rule: age must be 10+ and height 140 cm+ — both at once! Check it with and. (The inputs are 12 and 150.)
Inputs (for input())
One value per line — read in order by input().
Need an umbrella?
+15 XP ✓ CompletedA weather advisor with or: if there’s rain or wind, say Take an umbrella!, if neither, say The weather's great!. (In the inputs: rain yes, wind no.)
Inputs (for input())
One value per line — read in order by input().
Login system
+15 XP ✓ CompletedA login system like the real sites: the username and the password both have to be correct. (The correct pair is ready in the inputs.)
Inputs (for input())
One value per line — read in order by input().
🏅 You finished this module! Your program can make decisions now. In the next module we give it its biggest superpower: repetition. A computer can do the same task a million times without tiring — meet the for and while loops. Continue →