This review list is meant to give you an idea of the types of questions and topics that will be covered. It is by no means an exhaustive list. The actual exam will possibly contain questions and/or coding problems similar to those in this review guide, IN ADDITION to questions and/or coding problems related to any material gone over in lecture, group exercises, labs, homework assignments, course lecture notes, etc.
def foo(list, a): b = 0 c = len(list) - 1 while b <= c: d = (b + c) / 2 if a == list[d]: return d elif a > list[d]: b = d + 1 else: c = d - 1 return -1
win = GraphWin("Tic-Tac-Toe", 400, 400) win.setCoords(0.0, 0.0, 3.0, 3.0)
import _______________ import sys NUM_ARGS = ___________ words = {} if len(sys.argv) != ______________: print "This program needs a command-line argument" print "that is the name of the file to evaluate." sys._______________ file = open(_______________, 'r') for line in ____________: _____________ = string.split(line) for word in wordList: # change word to be in all lower-case word = string.lower(word) # if the word has punctuation after it if ord(____________) < ord('a') or ord(____________) > ord('z'): # remove the punctuation mark from the word word = word[: ___________ ] # put the word in the dictionary and/or increment the word counter count = words.___________(word, 0) words[ ____________ ] = count + 1 file.______________ print _____________
def drawTarget(radius): SIZE = 25 NUM_RINGS = 5 DELAY = 10 WHITE = 5 BLACK = 4 BLUE = 3 RED = 2 YELLOW = ________ window = ___________("Archery Target", SIZE * radius, SIZE * radius) ________.setBackground('green') counter = NUM_RINGS for i in range(radius * NUM_RINGS, _____, -radius): circle = _________(_______(SIZE * radius / 2, SIZE * radius / 2), ____) _______.setOutline('black') if counter == WHITE: circle._____________('white') elif counter == ___________: circle.setFill('black') ________ counter == BLUE: circle.setFill('blue') elif counter == RED: circle.setFill('red') elif counter == YELLOW: circle.setFill('yellow') else: _______ "Error - counter =", _________ circle.draw(___________) counter _____ 1 time.___________(DELAY) window._____________()
def foo(a): if a == 0: return 1 else: return a * foo(a - 1)
For the following question, no code is required. Just show what would be printed by the printStack() and printQueue() functions.
The following values are held in a queue:class Clock: def __init__(self, day, hour, min, sec): self.day = day self.hour = hour self.min = min self.sec = secwhere a Clock is to simulate a 24-hour clock by keeping the time in days, hours, minutes and seconds.
def foo(n): print n, if n > 0: foo(n - 1) def main(): foo(4) print 'done' main()
>>> colleagues = set(['Sam', 'Kostas', 'Dawn', 'Brooke', 'Marie', 'Dan']) >>> friends = set(['Dawn', 'Dan']) >>> acquaintences = friends.union(colleagues) >>> acquaintences
>>> colleagues.difference(friends)
>>> friends.difference(colleagues)
>>> colleagues.intersection(friends)
>>> acquaintences.issuperset(friends)