python · level 1 · unit 3 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Python is a calculator that never gets tired.
Each maths symbol is an . + adds, - takes away, * multiplies (a star, not an x) and / divides. Python works out the answer for you.
Dividing can leave bits. 7 / 2 gives 3.5, a : a number with a dot in it. Sharing 7 slices between 2? 7 // 2 gives 3 whole slices each, and 7 % 2 gives the 1 left over.
Like on paper, * and / happen before + and -. Brackets beat them all, so wrap the part you want worked out first.
print(7 / 2)
print(7 // 2)
print(7 % 2)
print(2 + 3 * 4)
print((2 + 3) * 4) Read % as "left over", not "percent".
guess first
Ten sweets, two friends. What will this show?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
sweets = 10
friends = 2
print(sweets / friends)
your turn
Your turn. Share out your stickers.
Choose how many stickers you have and how many friends get a share, then press run.
fix it
Two friends are splitting the bill. Something is off.
- Python does
/before+. Which number is being cut in half right now? - Only
drinksis being halved. You want pizza and drinks added together first. - Put brackets around
pizza + drinkson line 3, then press run.
nailed it
you made the computer do maths. :D
- Operators like
+,-,*and/do the maths. /gives a float.//and%give whole shares and leftovers.- Brackets first, then
*and/, then+and-.
new words in your collection
- float
- operator
This lesson isn’t saved. A free account remembers every lesson you finish.