←Previous page

03OPERATORS · COMPARE

Signs that ask a question.

A comparison sign looks at two values and answers True or False. Next, if will use those answers to choose a path.

IN REAL LIFE

Rules use comparisons.

At least, at most, more than: you hear these words every day.

Tall enough

You must be at least 120 cm tall to ride.

Bedtime

If it is later than 9, it is time to sleep.

Next level

Score 100 or more to unlock level 2.

WORDS INTO SIGNS

Say it with a sign.

SignIn wordsExampleAnswer
==the same as5 == 5True
!=not the same as5 != 3True
<less than3 < 2False
>more than3 > 2True
<=at most4 <= 4True
>=at least120 >= 130False

A trick: In <= and >=, the = always goes second. >= works, => does not.

STEP BY STEP

Can PyBot ride?

Each comparison gives its own True or False.

height = 125PyBot is 125 cm tall.
height >= 120Is 125 at least 120? True. PyBot can ride.
height >= 130Is 125 at least 130? False. Not the big ride yet.
height == 125Is it exactly 125? True.

LOOK FIRST

Three things to remember.

Two = ask

height = 125 fills a box. height == 125 asks a question.

Math first

2 + 3 == 5: Python does the math, then compares. True.

Capitals count

"cat" == "cat" is True, but "Cat" == "cat" is False.

RUN IT

Is PyBot tall enough?

Guess first. Then run real Python and check.

1

Guess the result

height = 125 print(height >= 120) print(height < 100)

What will Python show?

ride.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 125 to 120. Is 120 >= 120? Then change >= to >.

YOUR TURN

Compare with signs.

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

0Completed
10Not tried
0Review
01

Prize tickets

Rule: you need at least 10 tickets for the prize. Mia has 10 tickets.

Can Mia get the prize?

02

At least

10 >= 10

What does Python answer?

03

At most

7 <= 5

What does Python answer?

04

More than itself?

3 > 3

What does Python answer?

05

Different?

4 != 4

What does Python answer?

06

Math, then compare

2 + 2 == 4

What does Python answer?

07

Capital letters

"Cat" == "cat"

What does Python answer?

08

Write it right

PyBot wants to ask: is age at least 8?

Which line is right?

09

Fix PyBot's code

PyBot wins a prize with 10 points or more. It has exactly 10 points, but it shows False. Change the sign so it shows True.

Goal output
True
OUTPUT

Your work is saved here.

Want a fresh start? Clear only this page.

!
BIG IDEA

A comparison sign answers True or False.

Next: when a line has many signs, which one goes first?