The roller coaster
You ride if you have a ticket and you are tall enough. One missing? No ride.
06TRUE OR FALSE? Β· AND
and joins two questions. The answer is True only when both answers are True.
IN REAL LIFE
If one of the two is missing, the answer is no.
You ride if you have a ticket and you are tall enough. One missing? No ride.
I get a cookie if my homework is done and my room is tidy.
We ride if it is sunny and the tires have air.
TRUTH TABLE
Two questions can turn out four ways. and gives True in only one row.
has_ticket | is_tall | has_ticket and is_tall |
|---|---|---|
| True | True | True |
| True | False | False |
| False | True | False |
| False | False | False |
A trick: and is picky. One False is enough to make it all False.
STEP BY STEP
Python answers each question first. Then and joins the two answers.
age = 9A box keeps the number 9.if age >= 8 and age <= 10:9 >= 8? True. 9 <= 10? True. Both are True, so and gives True. print("PyBot is for you!")The answer was True, so this path runs.age = 12Now the box keeps 12.if age >= 8 and age <= 10:12 >= 8? True. 12 <= 10? False. One is False, so and gives False. print("PyBot is for you!")Skipped. The answer was False.RUN IT
Guess first. Then run real Python and check.
homework_done = True
room_tidy = False
if homework_done and room_tidy:
print("cookie time")
else:
print("not yet")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 False to True. What shows now? Then make both False.
YOUR TURN
Try each tiny question. A wrong answer becomes something to review.
Can Leo ride?
True and TrueWhat does Python answer?
sunny = True
warm = False
sunny and warmWhat does Python answer?
age = 12
age > 8 and age < 10What does Python answer?
coins = 5
if coins >= 3 and coins <= 10:
print("buy a toy")
else:
print("save more")What does Python show?
In the and table, how many rows give True?
How do you write βandβ in Python?
PyBot wrote && like other languages do. Python uses a word instead.
Enjoy the ride!OUTPUT
Want a fresh start? Clear only this page.
Next: or, which is happy with just one True.