Chapter 2-5 minutes required one sequence and the odd-numbered first N python

This problem requires programming, calculates the sequence 1 + 1/3 + 1/5 + ... and the first N.

Input format:
input line in a given positive integer N.

Output format:
output section and the value S in accordance with the "sum = S" format in a row, six decimal place. Title ensure that the calculation result does not exceed the double precision.

Sample input:
23

Output Sample:
SUM = 2.549541

n=int(input())
s=sum(1/(2*i-1) for i in range(1,n+1))
print("sum = %.6f"%s)
Published 14 original articles · won praise 1 · views 78

Guess you like

Origin blog.csdn.net/weixin_45948920/article/details/104345587