#!/usr/bin/env python3 """Algorithme d'Euclide Calcule le PGCD de deux nombres. """ import sys def main(): if len(sys.argv) == 3: a = int(sys.argv[1]) b = int(sys.argv[2]) else: a = int(input("a : ")) b = int(input("b : ")) calculate(a, b) def calculate(a, b): # Initialisation r = ["r", a % b] a = ["a", a] b = ["b", b] # Séquence while True: a.append(b[-1]) b.append(r[-1]) r.append(a[-1] % b[-1]) if r[-1] == 0: break print_table(a, b, r) print("Le PGCD est", r[-2]) def print_table(a, b, r): """Représentation de l'algorithme""" width = max((len(str(i)) for i in r)) for i in range(len(r)): print(f"{a[i]:^{width}} {b[i]:^{width}} {r[i]:^{width}}") if __name__ == "__main__": main()