 Simple coding

Start this free course now. Just create an account and sign in. Enrol and complete the course for a free statement of participation or digital badge if available.

Free course

# 6.1 The oldest algorithm

The while loop condition doesn’t have to be always true, of course. As an example, here is one of the oldest algorithms known, Euclid’s algorithm, used to find the greatest common divisor of two integers greater than zero, i.e. the greatest number that divides both without any remainder. For example, the greatest common divisor of 3 and 7 is 1, and of 21 and 49 is 7. This is needed to simplify fractions, for example. Explaining the maths that make the algorithm work is beyond the scope of this tutorial.

## Activity 11

Translate the algorithm below to Python. One instruction was already translated for you. Don’t forget to test your code.

Note that for the loop to end, the condition must become false, i.e. both variables n and m have the same value. Therefore it doesn’t matter which one you print.

SCOD_1