Python 3


PAGE 1/4
Sequences (successive commands)
Home >>> Free online lessons

We have already worked with them!

The programs written so far have used successive commands, which is represented by a sequence of instructions what happens every time we run Python code, regardless of the input values.

We read input data, assigned values, performed calculations, and then displayed the result in the console.


Suppose we want to create a program that reads three integers from the keyboard and displays their arithmetic mean.

The formula is simple. For a, b and c, the arithmetic mean is:

How do we create the algorithm?

Well ... we read the three values first and remember them as integers in the three variables, a, b and c. We define a variable named ma which will retain the arithmetic mean using the expression (a+b+c)/3. At the end we show the result, that is, the value retained by ma!

Take a look at the animated diagram below. Suppose values have been entered 9, 10 and 8:

Run the diagram

Then it's easier to do it in Python:
Editor -
Result in console done

Modify the above algorithm to display the geometric mean of the three numbers, using the calculation formula:

Next we will study together some elementary linear algorithms.
Execute the scheme, the program and solve the exercise.
 home   list  LESSONS   arrow_upward