""" This module lets you practice the ACCUMULATOR pattern in its simplest classic forms: SUMMING: total = total + number Authors: David Mutchler, Yiji Zhang, Mark Hays, Derek Whitley, Vibha Alangar, Matt Boutell, Dave Fisher, Sriram Mohan, Mohammed Noureddine, Amanda Stouder, Curt Clifton, Valerie Galluzzi, their colleagues and PUT_YOUR_NAME_HERE. """ # TODO: 1. PUT YOUR NAME IN THE ABOVE LINE. ############################################################################### # TODO: 2. Read the following, then change its _TODO_ to DONE. # Throughout these exercises, you must use RANGE statements. # At this point of the course, you are restricted to the SINGLE-ARGUMENT # form of RANGE statements, like this: # range(blah): # There is a MULTIPLE-ARGUMENT form of RANGE statements (e.g. range(a, b)) # but you are NOT permitted to use the MULTIPLE-ARGUMENT form yet, # for pedagogical reasons. ############################################################################### def main(): """ Calls the TEST functions in this module. """ run_test_sum_cosines() run_test_sum_square_roots() def run_test_sum_cosines(): """ Tests the sum_cosines function. """ # ------------------------------------------------------------------------- # TODO: 3. Implement this function. # It TESTS the sum_cosines function defined below. # Include at least ** 3 ** tests. # ___ # Use the same 4-step process as in implementing previous # TEST functions, including the same way to print expected/actual. # ------------------------------------------------------------------------- print() print("--------------------------------------------------") print("Testing the sum_cosines function:") print("--------------------------------------------------") def sum_cosines(n): """ What comes in: A non-negative integer n. What goes out: Returns the sum of the cosines of the integers 0, 1, 2, 3, ... n, inclusive, for the given n. Side effects: None. Example: If n is 3, this function returns cos(0) + cos(1) + cos(2) + cos(3) which is about 0.13416. Type hints: :type n: int :rtype: float """ # ------------------------------------------------------------------------- # TODO: 4. Implement and test this function. # Note that you should write its TEST function first (above). # That is called TEST-FIRST DEVELOPMENT (TFD). # ___ # No fair running the code of sum_cosines to GENERATE # test cases; that would defeat the purpose of TESTING! # ------------------------------------------------------------------------- def run_test_sum_square_roots(): """ Tests the sum_square_roots function. """ # ------------------------------------------------------------------------- # TODO: 5. Implement this function. # It TESTS the sum_square_roots function defined below. # Include at least ** 3 ** tests. # ___ # Use the same 4-step process as in implementing previous # TEST functions, including the same way to print expected/actual. # ------------------------------------------------------------------------- print() print("--------------------------------------------------") print("Testing the sum_square_roots function:") print("--------------------------------------------------") def sum_square_roots(n): """ What comes in: A non-negative integer n. What goes out: Returns the sum of the square roots of the integers 2, 4, 6, 8, ... 2n inclusive, for the given n. So if n is 7, the last term of the sum is the square root of 14 (not 7). Side effects: None. Example: If n is 5, this function returns sqrt(2) + sqrt(4) + sqrt(6) + sqrt(8) + sqrt(10), which is about 11.854408. Type hints: :type n: int :rtype: float """ # ------------------------------------------------------------------------- # TODO: 6. Implement and test this function. # Note that you should write its TEST function first (above). # That is called TEST-FIRST DEVELOPMENT (TFD). # ___ # No fair running the code of sum_square_roots to GENERATE # test cases; that would defeat the purpose of TESTING! # ------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Calls main to start the ball rolling. # ----------------------------------------------------------------------------- main()