CSSE 120 – Intro. to Software Development

Exam 2, Problem P7a Makeup

Due at the beginning of Session 24.

These problems are a make-up exercise for problem 7a on the paper part of Exam 2. Your score on this assignment will replace your score on that problem of the exam. If you earned 7 points out of the 7 available on the exam problem, then you do not have to complete this assignment.

  1. Review chapter 6.5 of Zelle on getting results from functions.
  2. In Eclipse, check out the project Exam2-P7aMakeup from your personal SVN repository.
  3. In the Exam2-P7aMakeup project, run the module exercises.py.
  4. Study the function fixResult() in exercises.py. The function does not satisfy its specification as given by its docstring. Fix the bug.

    When fixed, the first output of the program should be:

    Testing fixResult
    10 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 55
    -10 [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] 80
    
  5. Implement the function squareEach() so that it satisfies its specification as given by its docstring. When fixed, the output for this part of the program should be:

    Testing squareEach
    Before: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    After: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
    Before: [0, 2, 4, 6, 8]
    After: [0, 4, 16, 36, 64]
    Before: [1, 3, 5, 7, 9]
    After: [1, 9, 25, 49, 81]
    Before: [1, 2, 3, 4]
    After 1 iterations: [1, 4, 9, 16]
    After 2 iterations: [1, 16, 81, 256]
    After 3 iterations: [1, 256, 6561, 65536]
    After 4 iterations: [1, 65536, 43046721, 4294967296L]
    
  6. Consider the results of the testP7aCode() function. This function uses the code from problem 7a on Exam 2. Add a comment at the end of the testP7aCode() function explaining why the first two printed values don't change, but the third one does.