←Previous page

06TRUE OR FALSE? Β· AND

and: both must be True.

and joins two questions. The answer is True only when both answers are True.

IN REAL LIFE

Some rules need two things.

If one of the two is missing, the answer is no.

The roller coaster

You ride if you have a ticket and you are tall enough. One missing? No ride.

Cookie time

I get a cookie if my homework is done and my room is tidy.

Bike ride

We ride if it is sunny and the tires have air.

TRUTH TABLE

Every possible answer.

Two questions can turn out four ways. and gives True in only one row.

has_ticketis_tallhas_ticket and is_tall
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

A trick: and is picky. One False is enough to make it all False.

STEP BY STEP

Is PyBot for you?

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

Does PyBot get a cookie?

Guess first. Then run real Python and check.

1

Guess the result

homework_done = True room_tidy = False if homework_done and room_tidy: print("cookie time") else: print("not yet")

What will Python show?

cookie.pyREAL PYTHON
OUTPUT
Ready. Press Run Python.
Python runs here thanks to Pyodide β™₯

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

Both, or nothing.

Try each tiny question. A wrong answer becomes something to review.

0Completed
9Not tried
0Review
01

Roller coaster

Rule: you ride if you have a ticket and you are tall enough. Leo has a ticket, but he is not tall enough yet.

Can Leo ride?

02

Two yeses

True and True

What does Python answer?

03

One no

sunny = True warm = False sunny and warm

What does Python answer?

04

Between 8 and 10?

age = 12 age > 8 and age < 10

What does Python answer?

05

Toy shop

coins = 5 if coins >= 3 and coins <= 10: print("buy a toy") else: print("save more")

What does Python show?

06

Count the Trues

In the and table, how many rows give True?

07

Python's word

How do you write β€œand” in Python?

08

Fix PyBot's code

PyBot wrote && like other languages do. Python uses a word instead.

Goal output
Enjoy the ride!
OUTPUT

Your work is saved here.

Want a fresh start? Clear only this page.

!
BIG IDEA

and is True only when both answers are True.

Next: or, which is happy with just one True.