Homework Assignment
CS 121 (CS1)
- Homework 13 Due Wednesday, March 12, 2014
-
-
Strings [hc]
String questions, 1a and 1b (be sure to read the motivating introduction)
-
Images [hc]
-
Recursion [hc]
Recursion questions, 11d, 5, 6
-
Trees [hc]
Recursion questions, 12c and 12d
-
Review [hc]
Postponed
-
Lists [hc]
-
Lists, Exercises 4 (use loops), 6 (use
recursion, and no loops), 10 (use iteration and an accumulator)
- 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 listappend()
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
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.
count5Words(['apple', 'banana', 'cherry', 'grape']) --> 2 count5Words([]) --> 0
Hints:
-