>>    




Homework Assignment

CS 121 (CS1)

Homework 13   Due Wednesday, March 12, 2014
  1. Strings [hc]

      String questions, 1a and 1b (be sure to read the motivating introduction)

  2. Images [hc]

      Image questions, 6b

  3. Recursion [hc]

      Recursion questions, 11d, 5, 6

  4. Trees [hc]

      Recursion questions, 12c and 12d

  5. Review [hc]

      Postponed

  6. Lists [hc]

      Lists, Exercises 4 (use loops), 6 (use recursion, and no loops), 10 (use iteration and an accumulator)

      Hints:

      4
      • Use an accumulator to build up the list.

      • To add a new random number to the list, you may either use string concatenation (as we have done before), e.g.,

            lis = [42, 915]
            lis = lis + [707]
            lis --> [42, 915, 707]
        
        or the list append() method suggested in the problem.

        list.append

        One argument: Any Python3 value
        State change:
        The value arg1 is added as a new element at the end of a list object.
        Return: None
        Example call:
            lis = [42, 915]
            lis.append(707)
            lis --> [42, 915, 707]
        
      10
      Here is a spec.

      count5Words

      One argument: A Python 3 list of strings
      Return: A non-negative integer, the number of elements of arg1 that have length five.
      Example calls:
          count5Words(['apple', 'banana', 'cherry', 'grape']) --> 2
          count5Words([]) --> 0