← Back to course
Code Crew G4 / Week 04 / Monday
1/6
Week 04 Β· Choices in a loop

Monday

True or False?
// if, elif and else
⏱ about 15 min

Monday: True or False?

An alarm beeps in the storeroom. "Water is low!" Rocket says. "Let's build a program that warns us next time."

Raven floats to the shelf and counts three water tanks. "What do you notice?" she asks. "Low is just a feeling. A program needs a rule. Is three low? Is five low?"

Rocket scratches his head. Nova projects a number line in the air, with a glowing mark at five. "Would you like a hint? Python can compare two numbers and answer True or False."

Comparisons give True or False

A comparison asks a question about two values. Python answers with True or False. These answers are called Booleans.

water = 3
print(water < 5)
print(water > 5)
print(water == 3)
print(water != 3)
The screen shows
True
False
True
False
SignQuestion it asksExampleAnswer
<is it less than?3 < 5True
>is it greater than?3 > 5False
<=is it less than or equal to?5 <= 5True
>=is it greater than or equal to?4 >= 5False
==is it the same?3 == 3True
!=is it different?3 != 3False

Strings can be compared too. "oats" == "Oats" is False, because a small o and a big O are different letters.

ComparisonDoes Python say True?
8 > 5?
4 >= 4?
3 != 3?
10 < 2?
"tape" == "Tape"?
WHY THIS EXERCISEEvery if in a program depends on a comparison like these.
x = 7
print(x <= 6)
What does the program above show?
WHY THIS EXERCISEPython prints a Boolean as the word True or False.
PICK THE COMPARISON
  • Read the question.
  • Tap your answer.
A tank is full when it holds 10 or more units. Which comparison checks that?
Which comparison checks that the hatch is not "closed"?
Try it
Say a comparison out loud, like 6 is greater than 2.
Your grown-up answers True or False. Then swap.

Practice lab: check the oxygen

oxygen = 9
print(oxygen > 10)
print(oxygen <= 9)
print(oxygen != 4)
print("Dock" == "dock")
What does line 2 show?
What does line 3 show?
What does line 4 show?
What does line 5 show?
SIGNS AND ANSWERS
  • Read the question.
  • Tap your answer.
Which sign asks: is it different?
What does print(6 >= 6) show?
A shelf is low when it holds fewer than 3. Which check says True for a low shelf?
ComparisonDoes Python say True?
2 < 9?
9 <= 8?
"Go" != "go"?
5 > 5?
WHY THIS EXERCISEStrings compare letter by letter, so a capital letter makes them different.
x = 12 runs. What does print(x > 10) show?
WHY THIS EXERCISEPython prints the Boolean as the word True or False.

Nice work! You can read every comparison sign. Tomorrow your loops will use them to make choices.