Kids Coding
Numbers and Math
Add, subtract, multiply, divide. Python does the arithmetic. You choose the numbers.
Python can do maths
Numbers do not need quotes. 2 + 3 is maths. "2 + 3" is just the characters 2, space, plus, space, 3.
Add, subtract, multiply, divide
print(2 + 3)
print(10 - 4)
print(3 * 5)
print(8 / 2)The symbols
| Symbol | Meaning | Example |
|---|---|---|
+ | add | 2 + 3 is 5 |
- | subtract | 10 - 4 is 6 |
* | multiply | 3 * 5 is 15 |
/ | divide | 8 / 2 is 4.0 |
Division gives a number with a decimal, even when it divides evenly. 8 / 2 prints 4.0.
Print a label and a number
You can print text and a number in one line if you separate them with a comma. Python puts a space between them.
Score
print("Score:", 2 + 2 + 2)Real life
Buying snacks at the school stall.
You already do this in your head: 3 cookies times 2 coins. Python does the arithmetic.
Snack stall
cookies = 3
price = 2
print("Pay:", cookies * price)
print("Change from 10:", 10 - cookies * price)Change one word. Run it. That is how this idea shows up outside the lesson.
Try it
Exercise 1: Print the answer to 7 * 6, with the label Answer:.
Show solution
print("Answer:", 7 * 6)