Answer:
def sum_1k(M):
s = 0
for k in range(1, M+1):
s = s + 1.0/k
return s
def test_sum_1k():
expected_value = 1.0+1.0/2+1.0/3
computed_value = sum_1k(3)
if expected_value == computed_value:
print("Test is successful")
else:
print("Test is NOT successful")
test_sum_1k()
Step-by-step explanation:
It seems the hidden part is a summation (sigma) notation that goes from 1 to M with 1/k.
- Inside the sum_1k(M), iterate from 1 to M and calculate-return the sum of the expression.
- Inside the test_sum_1k(), calculate the expected_value, refers to the value that is calculated by hand and computed_value, refers to the value that is the result of the sum_1k(3). Then, compare the values and print the appropriate message
- Call the test_sum_1k() to see the result