

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


for i in range(2): for j in range(3): print i, j
What is printed?
(a) a constructor (b) a str method. The constructor is to take a breed, gender, and name (in that order) as string parameters and store them as a fields called breed, gender, and name. The str method is to return a string structured like this one: ”German Shepherd, male, named Spot” given the breed is German Shepherd, gender is male, and name is Spot. Be sure to name both the constructor and str methods correctly.
myDog = new Dog("male", "Wolfie") print string(myDog)
(a) In OO programming if you see the line myCard= Card(”Ace”, ”Hearts”), Card is actually a call to what?
(b) This is like a blueprint for objects in object-oriented programming. One writes this as the model for a given concept like Card, Deck, Student, Friend.
(c) When you store data for an actual instance using a class, you create one of these. (For example, you are storing a particular Card, a particular Friend, etc.)
(d) If you want to get a meaningful string representation of an object, then you should provide this method in your class.
(e) Functions in object-oriented programming go by this name instead.
(a) What is the Big O of sequential search?
(b) What is the Big O of binary search?
(c) What is the Big O of bubblesort?
(d) What is the Big O of selection sort?
(e) What is the Big O of quicksort?
[x for x in nums if x >= 0] What does that list comprehension do?
answers = map(math.sqrt, [100, 9, 49]) What does that call to map create?
The following code will result in a IOError in Python when the file is not found. Write a try/except block around the lines as given. Your try/except should be written so that if the IOError occurs, the program does not crash, but prints ”That file was not found” instead.
import os file = open("/User/blah.txt", "r")
Page 2