Slides badge

Maths and variables

Fix the program below by identifying the issues in it:

Print(Hello world!")
Print(Get_input())

Fix the program below by identifying the issues in it:

Print(Hello world!")
Print(Get_input())
print("Hello world!")
print(input())

Learning Intentions

  • Understand how to use maths in Python
  • Understand how to use variables in Python
  • Further our skills with input and output in Python

Success Criteria

  • I can develop my own calculator program
  • I can use maths in Python
  • I can explain why we use variables
  • I can write variables in Python

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 list of the different maths symbols we can use in Python:

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?

Algebra in Python

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

Python variables

y = 10
z = 2

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)

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 half of them go on holiday, how many of them went on holiday?
    • 2 or 3
    • Or would it be 2.5 people?
  • We cannot have a half person, so instead we have 2 remainder 1. 
  • Visit the website DIVISIONANDREMAINDERS and read the information on there.

Calculate the quotient and remainder for each of the following:

 

7 ÷ 3

9 ÷ 7

81 ÷ 21

Try it yourself

Remainder in Python

x = 9 / 4
y = 8 % 3

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")
  1. Write a program that will display the remainder of two numbers that the user enters. For example, they may type in 3 and 2, so the result would be 1.

Task

    • 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 tasks in the booklet from page 6 to page 17.

Task

Grade yourself

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

I can use variables to store data as well as maths in Python

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

Presentation Overview
Close
JB
Maths and variables
© 2020 - 2024 J Balfour
12:57 | 10-10-2024
Join Live Session
Start Remote
Save Progress
Slideshow Outline
Presenter Mode
Generate Quiz
Generate Lesson Plan
Widget Screen
Canvas Controls
Fullscreen
Random Selector
Timer
Volume Meter
Binary Converter
Python Editor
Show Knox 90
Provide Feedback
Help
!
Keywords
    DragonDocs Management
    Random selector
    Sections
      Binary conversion
      Denary to binary conversion
      Binary to denary conversion
      Feedback 👍
      Accessibility

      Apply a filter:

      ×
      Loading
      All slideshow files