3_2_3 Arithmetic operations in a programming language

You should be able to:

  • Be familiar with and be able to use:

•• addition

•• subtraction

•• multiplication

•• real division

•• integer division, including remainders.

REVISE:

PLEASE NOTE:

I have used the print() function a lot in these examples. This is because a student running the code would most likely be using it in an application. The print function allows the student to SEE what is happening with the piece of code that they are using. The print function can then be removed when used with the application.

Subtraction, Addition, Multiplication and Real Division

The operators that you need to know are:

  • + Add
  • - Subtract
  • * Multiply
  • / Divide

The next thing to remember is BIDMAS (Brackets, Indices, Multiplication, Addition and Subtract).

Watch the video below for an explanation.

Now that you are aware of BIDMAS you should be able to perform calculations in Python.

print (1+2)
print (1*2)
print (1-2)
print (1/2) # real division

This code will complete the simple calculations.

Remember that Python will default to the data type that it thinks that you are using. Because I haven't said otherwise, the final line of code will output as 0.5, which is real (float) and not an integer.

If I use the piece of code below instead then we are telling Python that it is an integer so it doesn't store the numbers after the decimal point.

print (int(1/2))

Integer division, including remainders [MOD]

What if we want to store the number as an integer but record the remainder?

If there is a pizza with 10 slices and three people are sharing the pizza then there will be 3 slice each with 1 remainder.

How could we work that out in Python?

pizzaSlices = 10
people = 3

slicesEach = int(pizzaSlices/people)
slicesLeft = (pizzaSlices%people)

print (slicesEach)
print (slicesLeft)

TEST:

  1. Download and print the test paper here: https://drive.google.com/open?id=0B5fLtQ0Xgr2PdGlVd2daVkFDOTg
  2. Try the mock test yourself.
  3. Use the 3.2.3 Walking Talking Mock below to guide you through answering the questions.

SOURCE RECOGNITION - PLEASE NOTE: The examination examples used in these walking talking mocks are samples from AQA from their non-confidential section of the public site. They also contain questions designed by TeachIT for AQA as part of the publicly available lesson materials.