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."
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 |
| Sign | Question it asks | Example | Answer |
|---|---|---|---|
| < | is it less than? | 3 < 5 | True |
| > | is it greater than? | 3 > 5 | False |
| <= | is it less than or equal to? | 5 <= 5 | True |
| >= | is it greater than or equal to? | 4 >= 5 | False |
| == | is it the same? | 3 == 3 | True |
| != | is it different? | 3 != 3 | False |
Strings can be compared too. "oats" == "Oats" is False, because a small o and a big O are different letters.
| Comparison | Does Python say True? |
|---|---|
| 8 > 5 | ? |
| 4 >= 4 | ? |
| 3 != 3 | ? |
| 10 < 2 | ? |
| "tape" == "Tape" | ? |
x = 7 print(x <= 6)
oxygen = 9
print(oxygen > 10)
print(oxygen <= 9)
print(oxygen != 4)
print("Dock" == "dock") | Comparison | Does Python say True? |
|---|---|
| 2 < 9 | ? |
| 9 <= 8 | ? |
| "Go" != "go" | ? |
| 5 > 5 | ? |
Nice work! You can read every comparison sign. Tomorrow your loops will use them to make choices.