#! /usr/local/bin/python3
# Code for evaluating an arbitrary polynomial and its derivative
# The polynomial is a[0] + a[1]*x + a[2]*x**2 + \ldots{} + a[n]*x**n
# C. DeTar September 10, 2017
# Usage
# poly.py
# When prompted, enter the degree of the polynomial followed
# by the coefficients a[0], a[1], ..., a[n]
# Then enter the value of x where you want to evaluate the polynomial
# and its derivative
import sys
######################################################################
def poly(n, a, x):
"""Evaluate a polynomial"""
p = a[n]
for i in range(n):
p = a[n1i] + x*p
return p
######################################################################
def main():
n = eval(input("Degree of polynomial = "))
a = [0 for i in range(n+1)]
print("Enter coefficients, a[0], a[1], ..., a[", n, "], one per line")
for i in range(n+1):
a[i] = eval(input())
x = eval(input("x = "))
p = poly(n,a,x)
print("P(", x, ") =", p)
######################################################################
main()
