Python and, or, not

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Python and, or, not

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which result does this give? age = 13 and True: print(age > 12 and age < 15)
A True
B False
2. score = 40. What does print(score > 50 and score < 100) show?
A True
B False
3. is_raining = True, has_umbrella = False. What does print(is_raining or has_umbrella) show?
A True
B False
4. Which sentence about or is correct?
A or is True only when both sides are True
B or is False only when both sides are False
5. What does print(not True) show?
A False
B True

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1age >= 12 and age <= 15 Aif score > 50 and time < 10:
2day == "Sat" or day == "Sun" BEach side of or needs a full condition. It should be: if x > 5 or x < 10:
3not reverses a condition: True becomes False and False becomes True CTrue only when BOTH conditions are True, so age must be from 12 to 15
4and needs both conditions True before the code inside the if runs Dand is a lowercase operator placed between two conditions, not a function. It should be: if age > 12 and age < 15:
5if x > 5 or < 10: ETrue when at least ONE condition is True, so it is a weekend day
6if And(age > 12, age < 15): Fif not raining:

Definitions

and, or, not

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
if age > 12 ___ age < 20: print("Teenager")
2.
if day == "Sat" __ day == "Sun": print("Weekend")
3.
raining = False if ___ raining: print("Play outside")
4.
sunny = True warm = False print(sunny __ warm)
5.
if score > 50 and ___ cheated: print("Pass")

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A age = 14
B has_pass = True
C print("Checking entry")
D ok = age >= 12 && has_pass
E print(ok)
Question 2
A a = True AND False
B b = True or False
C print(a)
D print(b)
Question 3
A sunny = True
B warm = False
C if sunny warm:
D print("Go outside")
Question 4
A raining = False
B print("Checking weather")
C if !raining:
D print("Leave umbrella")
Question 5
A ready = True and
B print(ready)
C print(not ready)

Answer Key

Python and, or, not
Section A: Quick Questions
Q1
A — True
Q2
B — False
Q3
A — True
Q4
B — or is False only when both sides are False
Q5
A — False
Section B: Match the Pairs
Q1
age >= 12 and age <= 15 → True only when BOTH conditions are True, so age must be from 12 to 15
Q2
day == "Sat" or day == "Sun" → True when at least ONE condition is True, so it is a weekend day
Q3
not reverses a condition: True becomes False and False becomes True → if not raining:
Q4
and needs both conditions True before the code inside the if runs → if score > 50 and time < 10:
Q5
if x > 5 or < 10: → Each side of or needs a full condition. It should be: if x > 5 or x < 10:
Q6
if And(age > 12, age < 15): → and is a lowercase operator placed between two conditions, not a function. It should be: if age > 12 and age < 15:
Section C: Definitions
Q1
and, or, not — Logical operators that combine or flip True/False conditions. and needs both True, or needs at least one True, and not reverses True to False (or False to True).
Section D: Fill in the Blanks
Q1
if age > 12 and age < 20: print("Teenager")
Q2
if day == "Sat" or day == "Sun": print("Weekend")
Q3
raining = False if not raining: print("Play outside")
Q4
sunny = True warm = False print(sunny or warm)
Q5
if score > 50 and not cheated: print("Pass")
Section E: Spot the Error
Q1
D — Python does not use && for 'and'. Write the word and: ok = age >= 12 and has_pass.
Q2
A — Python's logical operators must be lowercase. AND causes an error. It should be: a = True and False.
Q3
C — There is no operator between sunny and warm. Join the conditions with or: if sunny or warm:.
Q4
C — Python does not use ! for reversing a condition. Use the word not: if not raining:.
Q5
A — and needs a True/False value on both sides. The right side is missing. It should be: ready = True and True.