Exercise 7: Euclid's Greatest Common Divisor — Possible Solution ==================================================================== pairs = [(48, 18), (1071, 462), (17, 5), (100, 25)] for a, b in pairs: x, y = a, b while y != 0: x, y = y, x % y print(f"gcd({a}, {b}) = {x}") Example run: gcd(48, 18) = 6 gcd(1071, 462) = 21 gcd(17, 5) = 1 gcd(100, 25) = 25 WHY THIS WORKS AS AN ANSWER ------------------------------ x, y = y, x % y works because Python evaluates the whole right-hand side first and only then assigns, so neither variable is overwritten too early (in Java or JavaScript you would need a temporary variable). Each pass replaces the pair with the second number and the remainder, which keeps the greatest common divisor the same but makes the numbers smaller, so the loop must end. a and b are copied into x and y so the original pair can still be printed. The method needs no list of divisors and no guess about how many passes it will take.