# Lab 5, Task 5 (alternate) # CptS 111 # John B. Schneider # # Alternate implementation to calculate: # # f(x, k_max) = 1 + x + x ** 2 + x ** 3 + ... + x ** k_max # = x * (x * (x * (x * (1) + 1) + 1) + 1) + 1 # (where this is repeated k_max times) # def f(x, k_max): sum = 1.0 for i in range(k_max): sum = x * sum + 1.0 return sum