Start with
Edit:
Or, if you write your function as a function, you can use map/reduce to do the same thing much cleaner:
func = 1
before the loop, and then each time you calculate the new value, do func *= calculated_value
to multiply it into the rolling total.Edit:
Or, if you write your function as a function, you can use map/reduce to do the same thing much cleaner:
>>> import functools >>> import operator >>> def func(x): ... return 1 + (1/(x**2)) ... >>> functools.reduce(operator.mul, map(func, range(1, 19))) 3.482783207792457