I've written a program that calculates the infinite sum series by the formula. I've used a range function to calculate it but I came with a problem that range doesn't work with floats.
TypeError: 'float' object cannot be interpreted as an integer
I've tried to use numpy.arrange
but it helps only when you want to use step arrange(start, stop, STEP)
.
import math
import numpy
x = float(input('x: '))
n = float(input('n: '))
s = 0
while x >= 0.1:
for i in range(1, n + 1):
s = s + (math.pow(-1, i) * math.pow(x, 4 * i + 3)) / (numpy.factorial(2 * i + 1) * (4 * i + 3))
if x >= 1:
break
print(s)
UPD: this how my program looks like now:` import math import numpy
x = float(input('x: '))
n = int(input('n: '))
s = 0
while x >= 0.1:
for i in range(1, n + 1):
s = s + (math.pow(-1, i) * math.pow(x, 4 * i + 3)) / (math.factorial(2 * i + 1) * (4 * i + 3))
if x >= 1:
break
print(s)
` And such output:
W:\Labaratorni\Python\lab2_4\venv\Scripts\python.exe
W:/Labaratorni/Python/lab2_4/main.py
x: 0.3
n: 3
No errors, it just stops.