CS303E Practice Problems

1. What is the result of each expression?
Assume myTuple = (4,5,6).
a) x = myTuple[0]
b) x = myTuple[1:3]
c) myTuple[1] = 7
d) x,y,z = myTuple
e) myTuple = 7,8,9

2. What is the result of each expression?
a) setA=set([1,2,3,4,8,9,5,6,7,8,8])
b) print setA #Why is the result what it is?
c) setB = set([2,4,6,8,9,11,13])
setA | setB
d) setA & setB
e) (setA^setB) == ((setA-setB) | (setB-setA))

3. What is the result of each expression?
a) myDict = {"tennis":"racquet", "baseball":"bat"}
b) myDict["fencing"]="sword"
c) myDict["baseball"]="glove"
d) del myDict["fencing"]
e) myDict = []

4. Write a function makeDictionary() that takes the name of an input file as its argument. Your function creates and returns a dictionary that contains each lowercase character in the alphabet as a key ('a', 'b', 'c', ...); the value of each key is the number of occurrences of that character in the input file. Write a main function that prompts the user for the name of the input file, calls makeDictionary(), and then prints the number of occurrences of each lowercase character that occurs at least once.

5. Write a program that creates a graphical window with a cyan background. Create a yellow square, a thick red line, and 3 circles of different colors and sizes, and draw them on a window.