Comparison Operators

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

Comparison Operators

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does 10 > 5 return?
A True
B False
2. What does 3 == 3 return?
A False
B True
3. What does 7 != 7 return?
A False
B True
4. What does 4 < 4 return?
A True
B False
5. What does 5 >= 5 return?
A True
B False

Match the Pairs

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

Left columnRight column
1if x = 5: AOutput: False
2if 5 => 3: BOutput: True
3x = 5 x != 3 COk: >= means at least 50
4score >= 50 DValid: != checks not equal
5print(5 == 5) EError: Use == not = to compare
6print(3 > 10) FInvalid: Use >= not =>

Definitions

>

Fill in the Blanks

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

1.
print(10 _ 5)
2.
print(3 __ 3)
3.
print(7 __ 4)
4.
print(5 __ 5)
5.
print(2 __ 8)

Spot the Error

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

Question 1
A x = 5
B print(5 = 5)
C print(x + 1)
Question 2
A a = 10
B print(10 => 5)
C print(a)
Question 3
A x = 3
B y = 4
C print(3 =! 4)
Question 4
A n = 5
B print(5 =< 10)
C print(n)
Question 5
A x = 7
B print(7 < > 3)
C print(x)

Answer Key

Comparison Operators
Section A: Quick Questions
Q1
A — True
Q2
B — True
Q3
A — False
Q4
B — False
Q5
A — True
Section B: Match the Pairs
Q1
if x = 5: → Error: Use == not = to compare
Q2
if 5 => 3: → Invalid: Use >= not =>
Q3
x = 5 x != 3 → Valid: != checks not equal
Q4
score >= 50 → Ok: >= means at least 50
Q5
print(5 == 5) → Output: True
Q6
print(3 > 10) → Output: False
Section C: Definitions
Q1
> — Greater than - checks if the left value is larger than the right.~~<
Section D: Fill in the Blanks
Q1
print(10 > 5)
Q2
print(3 == 3)
Q3
print(7 != 4)
Q4
print(5 >= 5)
Q5
print(2 <= 8)
Section E: Spot the Error
Q1
B — Use == to compare, not = (which assigns)
Q2
B — Greater than or equal is >=, not =>
Q3
C — Not equal is !=, not =!
Q4
B — Less than or equal is <=, not =<
Q5
B — Use != for not equal <> is not valid Python