def integral(f, start, stop, width=0.0001): total = 0 # The accumulator i = start # The loop counter (counts by width) while i < stop: total += f(i) * width i += width return total # Test routine def f_easy(x): return 4 print("Should be 16: ", integral(f_easy, 0, 4)); def square_function(x): return x**2 print(integral(square_function, 1, 4)) :