computer4kids is now ComputerLeap. Same free lessons, same team. Read why we changed our name

← All lessons · 🧑‍💻 Coding Academy

🧮

🎓

⏱ 20 min

Free

Math Wizard

Python is a super calculator! Add, subtract, multiply, divide and turn text into numbers.

🎯 What you will learn

  • Do math with + – * /
  • Store numbers in variables
  • Turn input into a number with int()

👋 Let’s get started!

Python can do math faster than any wizard 🧙. Let’s use it to count candy, split pizza and solve puzzles!

🪜 Step by step

1. ➕➖✖️➗ Math signs

Python uses + – * and / for math.

print(7 + 3)
print(10 - 4)
print(6 * 7)
print(20 / 4)
2. 📦 Numbers in variables

Variables can hold numbers too — no quotes!

apples = 5
oranges = 3
print(apples + oranges)
3. 🔢 int() for answers

input() gives text. Use int() to turn it into a number before doing math.

age = int(input("How old are you? "))
print(age + 1)

🧪 Try it!

Change the code and press ▶ Run to see what happens. You can’t break anything!

Pizza party

slices = 12
friends = 4
print("Each friend gets", slices // friends, "slices 🍕")

Candy counter

candy = 20
eaten = 5
left = candy - eaten
print(left)

📖 Key words

Tap a card to flip it over!

Integer
A whole number like 7 🔢
int()
Turns text into a number 🔄
//
Divides and keeps the whole number ➗

🏆 Challenge

There are 3 boxes with 8 crayons each. Print the total number of crayons.

Challenge

boxes = 3
crayons_each = 8

Knowledge Check Quiz

  1. What does this print?
  2. What does this print?
  3. Why use int(input())?
← Previous lesson
Next lesson →