Skip to content

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:

WordMeaningIt’s true when…
andandboth conditions are true
ororat least one is true
notnotthe opposite of the condition is true
Inputs (for input())

One value per line — read in order by input().

Output
 

Write ticket = "no" and run it again — when and doesn’t see both sides as true, the whole condition becomes false.

Inputs (for input())

One value per line — read in order by input().

Output
 
Inputs (for input())

One value per line — read in order by input().

Output
 

not False becomes True, which is why the warning was printed. Try writing True and see.

Mission

Ride entry

+10 XP

Ride 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().

Output
 
Mission

Need an umbrella?

+15 XP

A 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().

Output
 
Mission

Login system

+15 XP

A 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().

Output
 

🏅 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 →