Jump to content

Jensen's Device: Difference between revisions

m
Line 114:
i = Ref()
def sum(ref_i, lo, hi, term):
# term is passed by-name, and so is i #
temp = 0;
for i in range(lo,hi+1):
ref_i.value = i;
temp += term()
return temp
# note the correspondence between the mathematical notation and the call to sum #
print (sum (i, 1, 100, lambda: 1.0/i.value))</python>
Output: 5.18737751764
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.