1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| def poly_to_str(poly):
exp = []
mnm = []
first = True
for n, a in enumerate(poly):
if not a:
continue
t_exp = str(n) if n > 1 else ""
if first:
t_mnm = ("{}X" if n else "{}").format(a)
first = False
else:
t_mnm = ("+ {}X" if a > 0 else "- {}X").format(abs(a))
exp.append(" " * len(t_mnm) + t_exp)
mnm.append(t_mnm + " " * len(t_exp))
return " ".join(exp) + "\n" + " ".join(mnm)
print([2, 33, 0, -666, 0, 0, 0, 0, 0, 0, 32.714, 0, 0, 0, 0, 0, 0, -0.3333333], " =>")
print(poly_to_str([2, 33, 0, -666, 0, 0, 0, 0, 0, 0, 32.714, 0, 0, 0, 0, 0, 0, -0.3333333])) |
Partager