https://www.programiz.com/online-compiler/5oVgX09CZEf1z
def f(x):
y= 1/(x**2)
return y
x0 = float(input("Enter lower limit of integration: "))
xn = float(input("Enter upper limit of integration: "))
n = int(input("Enter number of sub intervals: "))
h = (xn - x0) / n
sum = f(x0) + f(xn)
for i in range(1,n):
k = x0 + i*h
if i%2 == 0:
sum = sum + 2 * f(k)
else:
sum = sum + 4 * f(k)
sum = sum * h/3
print("Integration result by Simpson's 1/3rd rule is : ",sum)