A polynomial is given by its whole-number coefficients, highest power first: 3 0 -2 5 means 3x³ + 0x² − 2x + 5. Print its value and the value of its derivative at a whole number x.
Input
Two lines: the coefficients (1 to 20 whole numbers), then x.
Output
Two lines: f(x) = V and f'(x) = D, both whole numbers.
Examples
Example 1 · Input
3 0 -2 5 2
Expected output
f(x) = 25 f'(x) = 34
Example 2 · Input
1 0 0 3
Expected output
f(x) = 9 f'(x) = 6
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Coefficient i (counting from 0) belongs to the power n − i, where n is the number of coefficients minus 1.
Hint 2
The power rule turns c·xᵏ into c·k·xᵏ⁻¹; the constant term disappears.
Solution
Show one correct solution (try it yourself first)
coeffs = [int(c) for c in input().split()]
x = int(input())
n = len(coeffs) - 1
value = sum(c * x ** (n - i) for i, c in enumerate(coeffs))
slope = sum(c * (n - i) * x ** (n - i - 1) for i, c in enumerate(coeffs) if n - i > 0)
print("f(x) =", value)
print("f'(x) =", slope)