CS 303e
Exam 3 Review Sheet

This review sheet is not exhaustive. You will not be prepared for the exam if you only work the problems on this sheet.

Exam 3 will be comprehensive. Topics covered since the last exam include:
functions - parameters and return values, scope of variables, string processing,  lists, tuples, sets, dictionaries, graphics (windows, circles, lines, points, rectangles)
For lists, review these operations: append(), insert(), len(), indexing, slicing, list traversal (2 ways), list membership (e.g., n in myList), sort(), reverse(), index(), count(), pop(), remove(), del. Practice writing functions that take lists as arguments and/or return lists.
For strings, review these operations: find(), string traversal, string membership, indexing, len(), slicing, isalnum(), isdigit(), isalpha(), isspace(), islower(), isupper(), endswith(), startswith(), count(), strip()
For sets, review: union, intersection, difference, symmetric difference
For dictionaries: dictionary membership, over-writing a pair in the dictionary, keys(), values(), items(), dictionary traversal, get(), del
For graphics: constructing a graphical window, circle, rectangle, line, point. Drawing objects on a graphical window. Changing the background color of a window. Modifying the appearance of drawable objects by changing their width, setting their fill or outline color. Adding an arrow to a line.

The practice problems on this review sheet are not complete - it provides extra practice over topics that are covered on the exam, but it is not an exhaustive review of everything we've covered or everything that you will be asked on the exam. This sheet is no substitute for reviewing your class notes and re-working examples and exercises that we did in class.

I will not provide solutions for these problems. You will have time to ask questions about them in discussion, class and office hours before the exam.

1. Re-work the review sheets for exam 1 and exam 2.

2. Re-work the examples and exercises that are described in the online class notes or that were assigned through discussion assignments or puzzlers.
3. Create a dictionary that contains key-value pairs, in which the key is a person's name (a string) and the value is a phone number. Read a file phonelist.txt that has the following format:
Add all the entries in the file to your dictionary. If a name occurs more than once, the value associated with that name should be the last number given for that person. For the above file, the dictionary should look like this:
{'Nancy': '222-3456', 'Sam':  '288-9000', 'Elvis': '366-7666'}

4. Write a function getFew(alist, num) that takes a alist and an integer num, and returns a list that contains the first num values in alist. If num is not positive, return an empty list. If num is greater than the length of alist, return a copy of alist.
getFew([1, 7, 6, 5], 2) --> [1, 7]
getFew(["apple", "peach", "melon", "kiwi"], -3) --> []
getFew([18, 5, 3], 5) --> [18, 5, 3]

5. Read a string from the user, and then print the following:
6. Prompt the user to enter 2 strings, and then print:
7. Write a graphics program that creates 10 white nested rectangles in a window with an orange background.

8. Read 20 strings from the user, and print the length of these strings to a file lenOutput.txt, one value per line.

9. Write a function makeList(s) that takes a string s, and returns a list containing the letters and digits stored in s. For example:
makeList("hello, hey!") --> [h, e, l, l, o, h, e, y]
makeList("\nTalk $ \t1-800\n") --> [T, a, l, k, 1, 8, 0, 0]

10. Write a Python function getDigits(st) that takes a string st, and returns a list that contains all the digits in st.

11. Create a list that contains 10 strings that you read from the user. Sort this list, and print the strings to the screen both before and after you sort.

12. Explain in detail how remove() works when it is called on a list. What happens if you attempt to remove a value that is not in the list? How do remove() and pop() work differently?

13. Which sequence types are mutable, and which are immutable?

14. Describe an application in which sets would be useful.

15. Write python code that displays the following output. You may only print one character at a time.


16. Write python code that displays the following output, printing only one character at a time.


17. What is the value of x after the code is executed?

s = 'kelp'
for y in s:
    x = y

x = 44%3 + 44/3

c) s = [3, 4, 11, 98, 222]
x = s[-3]

d) s = [3, 4, 11, 98, 222]
x = s[:2]

e) x = string.find("elvis lives", 'i')

f) l = [2, 3, 5, 77]
x = l

18. Write a function convert(num) that takes an integer num and returns a list that contains the digits of num.

19. Write a python program that draws 10 nested circles in a graphical window.