Exercises
September 27 - September 29, 2006
To ensure that you receive appropriate laboratory credit, for each
exercise make sure that I have looked at your source code and seen
a demonstration of your working program.
- Use the interpreter to help you determine the outcome of each of the
following statements. Why are the invalid statements invalid?
list1 = [1,2,3]
list2 = list1
print list2
list2 = list1[2]
print list2
list2.append(8)
print list2
list2 = list1
list2.append(8)
print list2
list1[9] = "hello"
print list2
list1[2] = "hello"
print list2
- Implement a program that prompts the user for a series of strings
(using “quit” to end input) and stores them in a list. Then,
for every string in the list, display it for the user and ask if he/she
would like to delete it. Delete the appropriate strings and display the
final list for the user.
- Implement a function that takes as input a list of integers and adds
5 to every element.
- Implement a program that prints all elements in a
matrix.
- Can you think of a way to write a function that takes as input a tuple
of integers, adds 5 to every element, and returns a tuple?
Sami Rollins