#! /usr/bin/env python from sys import stdin # read polynome from stdin print(f"Input Coefficients line by line, last line is x0, Press Ctr+D to finish!") lines = [] for line in stdin: koeffizient = line.strip() if koeffizient[0] == "#": continue if len(koeffizient) > 0: lines.append(float(koeffizient)) else: break a = lines[0:-1] b = lines[-1] b = float(b) p = a[-1] c = [p] for ak in a[-2::-1]: p = ak + (p * b) c.insert(0, p) p_b = c[0] c = c[1:] print(f"p(x) =", a) print(f"p({b}) = {p_b}") print(f"c(x) =", c)