BCS_Workshop_Apr_20
BCS_Workshop_Apr_20 copied to clipboard
one value error at function examples
:
simple python function
def poly(poly_idx, x): value = 0 l = len(poly_idx) - 1
for i in range(l+1):
value += poly_idx[i]*(x**(l-i))
return value
print("x^2 + x + 1 at x = 0 is:", poly([1, 1, 1], 0)) print("x^2 + x + 1 at x = 1 is:", poly([1, 1, 1], 1)) print("x^2 + x + 1 at x = 2 is:", poly([1, 1, 1], 2)) print("2x^2 + x + 1 at x = 2 is:", poly([2, 1, 1], 1))
here in the last line it should be x=1
Hey thanks, I will correct that