# test_passing_function.py def f(x): return x*x def trap_int(f, xmin, xmax, nstep): # integrate f(x) from xmin to xmax area=(f(xmin)+f(xmax))/2.0 h = (xmax-xmin)/nstep for i in range(1,nstep): x = xmin+i*h area = area + f(x) return area*h # trapezoidal method print "test_passing_function.py running" xmin = 1.0 xmax = 2.0 n = 10 area = trap_int(f, xmin, xmax, n) print "trap_int area under x*x from ",xmin," to ",xmax," = ",area