I'm trying to write a code that calculates integrals using the rectangular rule and also allows the user to input the integral limits and number of divions(rectangles). I've written the function, but for certain values it just returns "None". Any idea why?
Here's my code so far:
def integral(f, a, b, N):
h = int((b-a)/N)
result = 0
result += h * f(a)
for i in range(1, N-1):
result += h * f(a + i*h)
return result
def f(x):
return x**3
string_input1 = input("Please enter value for a: ")
a = int(string_input1)
string_input2 = input("Please enter value for b: ")
b = int(string_input2)
while True:
string_input3 = input("Please enter integer positive value for N: ")
N = int(string_input3)
if N>0:
break
print(integral(f, a, b, N))
an example of values that return "None" is a=0 b=1 N=2