Skip to content
Skip to main content

About this free course


Download this course

Share this free course

Simple coding
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.

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 10

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

Interactive feature not available in single page view (see it in standard view).

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.