Pursuit of a sequence of N odd minutes ago and (15 minutes)

Chapter 2-5 before seeking odd-number sequence and the N items (15 minutes)

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

Input formats:

In a given input row positive integer N.

Output formats:

And output portion of 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

Sample output:

sum = 2.549541

Code

print("sum = {:.6f}".format(sum([1/(2*i+1) for i in range(int(input()))])))

Guess you like

Origin www.cnblogs.com/nonlinearthink/p/10991507.html