Problem 1
For a given n
, compute the sum:
s = 1 / (1**2) + 1 / (2**2) + … + 1 / (n**2)
For n == 0
, the sum should be 0.
For n == 4
, the sum should be about 1.42.
Functions:
compute (n)
|
Compute the recursive sum s = 1 / (1**2) + 1 / (2**2) + … + 1 / (n**2) . |
-
compute(n: int) → float[source]
Compute the recursive sum s = 1 / (1**2) + 1 / (2**2) + … + 1 / (n**2)
.
>>> compute(4)
1.4236111111111112
- Requires
-
- Ensures
-