#exercise 3.7 from A primer... #a) function for computing the sum: def sum_1k(M): s = 0.0 for k in range(1,M+1): s = s + 1.0/k return s #b) test function def test_sum_1k(): expected = 11.0/6 computed = sum_1k(3) tol = 1e-10 success = abs(expected-computed) < tol msg = f'Expected {expected}, but got {computed}' assert success, msg """ About calling test functions: If we include a call to the test function here, the test is run when we type 'python sum_func.py' in the terminal window. Alternatively, we can run 'pytest sum_func.py', which will run all test functions found in the file, regardless of whether or not they are called.""" test_sum_1k() """ Terminal> python sum_func.py no output """