From 703341f2678585c0dd2f10efe1e7da69177c7981 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@pinebookpro" Date: Mon, 17 Jan 2022 13:00:58 +0100 Subject: [PATCH] Add column width --- algebre-non-lineaire/euclide_etendu.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/algebre-non-lineaire/euclide_etendu.py b/algebre-non-lineaire/euclide_etendu.py index 850cc18..d1ec526 100755 --- a/algebre-non-lineaire/euclide_etendu.py +++ b/algebre-non-lineaire/euclide_etendu.py @@ -7,6 +7,7 @@ Calcule le PGCD de deux nombres et trouve les coefficients de Bezout. import sys + def main(): assert len(sys.argv) == 3 a = int(sys.argv[1]) @@ -30,10 +31,14 @@ def main(): print_table(r, u, v, q) + def print_table(r, u, v, q): """Représentation de l'algorithme""" + + width = max((len(str(i)) for i in r)) + for i in range(len(r)): - print(f"{r[i]:^5} {u[i]:^5} {v[i]:^5} {q[i]:^5}") + print(f"{r[i]:^{width}} {u[i]:^{width}} {v[i]:^{width}} {q[i]:^{width}}") if __name__ == "__main__":