Slides badge

Maths and variables

Fix the program below by identifying the issues in it:

Print(Please enter your name")
Print("Hello there " Get_input()

Fix this program:

 

 

 

 

Fix the program below by identifying the issues in it:

print("Please enter your name")
print("Hello there " + input())

Fix this program:

 

 

 

 

  • How to use maths in Python
  • How to use variables in Python
  • To further our skills with input and output in Python
  • Be able to use maths in Python
  • Be able to explain why we use variables
  • Be able to write variables in Python
  • Be able to develop your own calculator program

Reminder!

  • In the last lesson we looked at getting an input from the user.
  • Remember that if we want Python to treat that input as a number we need to use int.
x = 5
y = int(input("Please enter y"))

z = x * y
print(z)

Maths in Python

  • Maths in Python is very similar to how it is done in actual maths. For example, in maths you write 5 + 5 and in Python we just write 5 + 5.
  • Here is a table of the different maths symbols we can use in Python:
Maths symbol Python symbol Purpose
+ + Addition
- - Subtraction
× * Multiplication
÷ / Division
% % Modulus (get the remainder)

Maths in Python

print(5 + 5)
print(5 - 5)
print(5 * 5)
print(5 / 5)

print(5 + int(input()))

Algebra

 

y = 10

z = 2

 

x = y × z

 

What is x equal to?

Getting the remainder

  • When performing a division of two numbers, e.g. x and y, the number you get back from this is called the quotient.
  • Thinking about a group of five people. If exactly half of them go on holiday in at the one time, how many of them go on holiday each time?
    • 2 or 3
    • Or would it be 2.5 people?
  • We cannot have a half person, so instead we have 2 remainder 1. 
  • In Python, we use the % symbol to get the remainder of a division sum:
print(5 % 2)

Calculate the quotient and remainder for each of the following:

 

13 ÷ 5

9 ÷ 7

81 ÷ 21

Example

2 r 3

1 r 2

3 r 18

7 ÷ 3

Calculate the quotient and remainder for

3 × 2 = 6

 

7 - 6 = 1

 

2 r 1

List the multiples of 3 until they are bigger than 7 and stop. 

Remainder in Python

print(9 / 4)
print(9 % 4)

Mathematical symbols in Python

Variables

  • Python uses something called variables to store data in the same way we use x, y and z in algebra.
  • Variables are like a box that contains a single value:

Variables in Python

Python variables

y = 10
z = int(input("Please enter a number"))

x = y * z

print(x)

Why do we use variables?

  • Variables store values in main memory so we can get the value from them later.
  • If we take a user’s input and we want to add 5 to it and then print it, we would get a long statement.
  • Variables make code easier to read.
print(int(input()) + 5)
user_input = int(input())
x = user_input + 5
print(x)

Even and odd numbers

  • Any number when divided by 2 which gives a remainder of 0 is an even number.
  • Any number when divided by 2 which gives a remainder of 1 is an odd number.

 

  • To use this, we can write an if statement to check this:
number = 7

if number % 2 == 0:
  print("This is an even number")

Check your understanding

x = 5
y = x
x = 10
print(y)

What will this program print?

y

5

10

z = 10
x = 10
y = 3
z = y * y
print(z)

6

10

16

Check your understanding

x = 5
y = x
x = 10
print(y)

What will this program print?

y

5

10

z = 10
x = 10
y = 3
z = y * y
print(z)

9

10

16

    • Create a program to take a person’s name in and store it in a variable
    • Print the user’s name on to the screen

    Challenge

    • Create a program that takes in two numbers and stores them in variables
    • Create a third variable that stores the result of these two numbers being added together
    • Print the third variable to the screen

     

  1. Complete all the tasks on the worksheet.

Task

Grade yourself

I can use maths in Python to add, subtract, multiply and divide several numbers

I can write a program using variables that stores the user's input in a variable

I can write a simple calculator program that takes two numbers and performs an operation on them

Presentation Overview
Close
JB
© 2020 - 2026 J Balfour
!
Keywords
    DragonDocs Management
    Random selector
    Set a timer for how long?
    10:00
    5:00
    3:00
    2:30
    2:00
    1:00
    ...
    Sections
      Binary conversion
      Denary to binary conversion
      Binary to denary conversion
      Feedback 👍
      Accessibility

      Apply a filter:

      Apply theme

      Blue theme
      White theme

      More effects:

      ×
      Loading
      All slideshow files