128. Python Program to Compute the Given Series 1/1 + 1/3 + 1/5 + 1/7 + ……. + 2.5
How does this program work?
- This program is used to find the Sum of the given series 1/1 + 1/3 + 1/5 + 1/7 + ……. + 2.5 using Python.
- The integer entered by the user is stored in variable n .
- By using the for loop condition we can easily calculate the sum of given series.
Here is the code
n = int(input( "Enter a number: "))
s = float(0.0)
for i in range(1,n):
if(i%2!=0):
s+= (float(1)/float(i))
i+=1
print("Sum of the series: %.4f " %s)