**THE PROBLEM** The euclidian algorithm calculates the greatest common divisor (gcd) of two integers a and b. pgcd (a, b) is the largest integer p that divides a and b, knowing that: - If a is divisible by b, pgcd (a, b) = b. - Otherwise, by setting r the remainder of the integer division of a by b, pgcd (a, b) = pgcd (b, r) By setting q the quotient of the integer division of a by b, let us calculate for example the gcd of 90 and of 35 (gcd (90,35), so a = 90 and b = 35): a = b × q + r As for 90/35 we have q = 2 and r = 20, then 90 = 35 × 2 + 20 **According to Euclid, pgcd (90.35) = pgcd (35.20). So we start over with the new values: 35 = 20 × 1 + 15 According to Euclid, pgcd (35.20) = pgcd (20.15). So we start over with the new values: 20 = 15 × 1 + 5 According to Euclid, pgcd (20.15) = pgcd (15.5). So we start over with the new values: 15 = 5 × 3 + 0 15 is divisible by 5 so we stop and pgcd (15.5) = pgcd (20.15) = pgcd (35.20) = pgcd (90.35) = 5.** Write the code of the euclid function (a: int, b: int, verbose: bool = False) -> int which calculates the gcd of a and b and, if the verbose parameter is True, displays the different steps of the algorithm of the calculation (the values of a, b, q and r).
What I’ve done (it’s false i know, idk how to do this…)
def euclide(a,b,verbose = False): r=a%b q=a//b if a%b == 0: verbose = True print(a) print(q) print(r) return b else: while r != 0: a = b b = r a = b * q + r print(euclide(90,35))
Idk how to get the bold part above in the program
I couldn’t tell but I have no idea how to do this, even the related posts are not that related to this and don’t answer the question…