Hong-Phuc Bui
2024-06-17 689ada49c2f083fcb3a2eeafc2ac15954ed64eca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /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)