Learn / Python Level 1

Lesson 3: Numbers and maths

By the end you can: Do maths in Python and turn typed answers into numbers.

1Recall

Question 1

1. What does name = input("Name? ") do?

Question 2

2. If animal = "cat", what does print("A " + animal) show?

Question 3

3. Which name breaks the rules?

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

Question 1

1. What is 10 // 3?

Question 2

2. What is 10 % 3?

Question 3

3. Why do we write int(input("Age? "))?

7At home

8Reflect

  • Where could a program like the pizza party help in real life?
  • What happened when you forgot int()? Why?
Next: Lesson 4, Making decisions →