Highest Common Factors – Euclid's algorithm

Step 3 – the loop and taking numbers away

The business part of the program is the loop.

Remember, all this does is take numbers away from each other until they are the same.

Scratch code image

  1. The loop in Python needs to be a WHILE loop

    THEORY: The loop uses the key idea of repetition – doing a series of instructions more than once.

  2. Just like in Euclid's algorithm, we keep going all the time the variables are NOT EQUAL TO each other
  3. In Python NOT EQUAL TO is !=

    THEORY: This is using selection. We're choosing a path to take in the program.

  4. Then we check which number is biggest and take the smallest number away from the biggest number

    THEORY: This changes the value of one of the variables each time.

  5. Don't forget to indent code carefully
  6. IMPORTANT: don't forget what your Python variables are called!

  7. Save your program
  8. Run your program
  9. Run it several times to check it always works right and to correct any errors

Code helper image