Dark theme

Add three numbers


Here's your first Python code - it implements the algorithm for adding three numbers. See if you can understand it, and note how the algorithm is written into the code. It's usual to write down the algorithm as comments (which the computer doesn't run) and build the code around it.

#
# Program to calculate the mean of three numbers
# Author: Andy Evans
#

#Get 3 numbers.
numberOne = 7
numberTwo = 23
numberThree = 42

# Sum the numbers.
sum = numberOne + numberTwo + numberThree

# Divide the sum by 3.
result = sum/3

# Print the result.
print (result)

Once you get used to running Python code, you might want a copy of this in a suitable version for compiling, in which case here's the source code version: calculate.py.

When you're ok with this lot, go back to the materials.