Calculations

At National 5, performing calculations within your code is very common.

Key Points

Calculations are a very common coding task at National 5.

You must know addition, subtraction, division, and multiplication.

Calculations follow the rules of BODMAS.

Simple Calculations

At National 5 you must be able to perform the following calculations.

The following code adds two numbers to together and stores the answer as “answer”. The answer is then printed out for the user.

number1 = 10
number2 = 5

answer = number1 + number2

print(answer)

The following code subtracts number2 from number1 and stores the answer as “answer”. The answer is then printed out for the user.

number1 = 10
number2 = 5

answer = number1 - number2

print(answer)

The following code multiplies two numbers and stores the answer as “answer”. The answer is then printed out for the user.

number1 = 10
number2 = 5

answer = number1 * number2

print(answer)

The following code divides number1 by number2 and stores the answer as “answer”. The answer is then printed out for the user.

number1 = 10
number2 = 5

answer = number1 / number2

print(5)

National 5 Requirements

You must be able to perform each of the calculations in your code.