N seek before interleaving sequence and (15 minutes)

Chapter 2-6 before seeking interleaved sequence of N and (15 minutes)

This requires programming problem, the sequence of staggered 1-2 / 3 + 3 / 5-4 / 7 + 5 / 9-6 / 11 + ... and the first N.

Input formats:

In a given input row positive integer N.

Output formats:

Value output portion and in a row, the results of three decimal places.

Sample input:

5

Sample output:

0.917

Code

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

Guess you like

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