Who is taller?
My big sister is taller than me. True!
06COMPARISONS
Every if asks a question. The answer is always True or False. Here you learn to write those questions.
IN REAL LIFE
Who is taller? Do we have the same? Each question has a yes or no answer.
My big sister is taller than me. True!
My cousin and I are both 9. Same age? True!
I have 3 candies and my friend has 5. Do I have more? False.
LOOK FIRST
A Python question has only two answers: True or False. They start with a capital letter, like the yes-or-no box.
3 < 5 asks: is 3 less than 5? Python answers True.
One = puts a value in a box. Two == ask if two values are the same.
THE COMPARISON SIGNS
| Sign | It asks | Example | Answer |
|---|---|---|---|
== | Are they the same? | 4 == 4 | True |
!= | Are they different? | "cat" != "dog" | True |
< | Is the left one smaller? | 7 < 2 | False |
> | Is the left one bigger? | 9 > 3 | True |
<= | Smaller, or the same? | 5 <= 5 | True |
>= | Bigger, or the same? | 6 >= 10 | False |
A trick: < and > are like a hungry mouth. The open side always faces the bigger number.
JOIN QUESTIONS
Sometimes one question is not enough. These three words help. Each one gets its own page next.
sunny and warm is True only when sunny is True and warm is True.
cake or ice_cream is True when at least one of them is True.
not True is False. not False is True.
RUN IT
Guess first. Then run real Python and check.
battery = 50
sunny = True
if battery > 30 and sunny:
print("play outside")
else:
print("stay inside")What will Python show?
PyBot's hint
Ready. Press Run Python.
Pyodide 314.0.3 runs CPython in your browser with WebAssembly.
Open-source under the Mozilla Public License 2.0. License
Now change one thing: Change True to False. Which path runs now? Then try battery = 10.
YOUR TURN
Try each tiny question. A wrong answer becomes something to review.
Ana has more stickers than Leo. True or False?
3 < 5What does Python answer?
7 == 8What does Python answer?
score = 10
score == 10Which line asks a question?
"cat" != "dog"What does Python answer?
has_ticket = True
is_tall = False
has_ticket and is_tallWhat does Python answer?
raining = False
snowing = True
raining or snowingWhat does Python answer?
not TrueWhat does Python answer?
PyBot wants to ask a question, not store a value.
Three stars!OUTPUT
Want a fresh start? Clear only this page.
if uses that answer to choose a path. Next: join two questions with and.