โ†Previous page

03OPERATORS ยท MATH

Python is a super calculator.

An operator is a sign that does a job with two values. Python has seven math signs. Three are new: //, %, and **.

IN REAL LIFE

You do math every day.

Sharing, making groups, and counting tiles are math with operators.

Share a pizza

8 slices for 4 friends: 8 / 4 is 2 slices each.

Candies left over

7 candies for 2 kids: 3 each, and 1 is left over.

Square tiles

A floor 3 tiles long and 3 wide has 3 ร— 3 = 9 tiles.

THE MATH SIGNS

Seven math signs.

SignIt doesExampleAnswer
+Adds7 + 29
-Takes away7 - 25
*Multiplies7 * 214
/Divides, with decimals7 / 23.5
//Divides, whole part only7 // 23
%Gives what is left over7 % 21
**Power: times itself7 ** 249

Remember: You met + - * / in Changing boxes. The new ones are // for the whole part, % for the leftover, and ** for power.

STEP BY STEP

Share the candies.

Python can tell how many each kid gets and how many are left.

candies = 77 candies.
kids = 22 kids.
each = candies // kids7 // 2 is 3. Each kid gets 3.
left = candies % kids7 % 2 is 1. One candy is left over.
print(each, left)Shows 3 1.

RUN IT

Share PyBot's candies.

Guess first. Then run real Python and check.

1

Guess the result

candies = 7 kids = 2 print(candies // kids) print(candies % kids)

What will Python show?

share.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 7 to 10 candies. Then try kids = 3.

YOUR TURN

Use the math signs.

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

0Completed
10Not tried
0Review
01

Make teams

6 kids want to make teams of 4.

How many full teams, and how many kids are left?

02

One slash

print(9 / 2)

What will Python show?

03

Two slashes

print(9 // 2)

What will Python show?

04

What is left?

print(10 % 3)

What will Python show?

05

Even or odd?

print(8 % 2)

What will Python show?

06

Times itself

print(3 ** 2)

What will Python show?

07

Three times

print(2 ** 3)

What will Python show?

08

Pick the sign

PyBot has 20 stickers and puts 6 on each page.

Which line gives the stickers left over?

09

Fix PyBot's code

PyBot shares 12 cookies with 3 friends. It wants a whole number, but it shows 4.0. Change one sign so it shows 4.

Goal output
4
OUTPUT

Your work is saved here.

Want a fresh start? Clear only this page.

!
BIG IDEA

Each math sign does one job.

// gives the whole part, % the leftover, and ** the power. Next: signs that compare.