Lesson 3: Numbers and maths
By the end you can: Do maths in Python and turn typed answers into numbers.
1Recall
2New idea
Python is a great calculator. Numbers don't need quotes, and you can use maths symbols directly.
- + add, - subtract, * multiply, / divide
- // divides and drops the remainder: 7 // 2 is 3
- % gives only the remainder: 7 % 2 is 1
- Brackets work like in maths: (2 + 3) * 4 is 20
Watch out: input() always gives back text. "5" + "5" is "55", not 10! Use int() to turn text into a whole number before doing maths.
3Show me
A pocket-money calculator. Try different answers.
Sharing sweets: // and % in action.
4Challenge 1
5Challenge 2
6Check
7At home
8Reflect
- Where could a program like the pizza party help in real life?
- What happened when you forgot int()? Why?
