I'm trying to create a program that lets me calculate x(i)=1/i^2 for i=1,2,⋯,N
Here is my code so far:
end = int(input("How many times do you want to calculate it?: "))
x = 0.0
for i in range (0, end):
x = x + (1 / end **2)
print ("The sum is", x)
You aren't using your increment i
.
You are also dividing by zero.
Try:
end = int(input("How many times do you want to calculate it?: "))
x = 0.0
for i in range (1, end+1):
x = x + (1 / (i**2))
print ("The sum is", x)
That should provide the result you are looking for. Enjoy!