1.
You run the code below in idle.
type(5)
print(3.0-1)
What's printed?
A. 
B. 
C. 
D. 
2.
Which is allowed in Python?
A. 
B. 
C. 
D. 
3.
You run the code below from the file editor.
usa_gold = 46
uk_gold = 27
romania_gold = 1
total_gold = usa_gold + uk_gold + romania_gold
print(total_gold)
romania_gold += 1
print(total_gold)
What is printed?
A. 
B. 
C. 
D. 
4.
What is the value of variable `u` from the code below?
once = "umbr"
repeat = "ella"
u = once + (repeat+" ")*4
A. 
B. 
C. 
D. 
5.
What does the code below print?
pset_time = 15
sleep_time = 8
print(sleep_time > pset_time)
derive = True
drink = False
both = drink and derive
print(both)
A. 
B. 
C. 
D. 
6.
What's printed when x = 0 and y = 5?
x = float(input("Enter a number for x: "))
y = float(input("Enter a number for y: "))
if x == y:
if y != 0:
print("x / y is", x/y)
elif x < y:
print("x is smaller")
else:
print("y is smaller")
A. 
B. 
C. 
D. 
7.
What is printed when the below code is run?
mysum = 0
for i in range(5, 11, 2):
mysum += i
if mysum == 5:
break
mysum += 1
print(mysum)
A. 
B. 
C. 
D. 
8.
What does the code below print?
s = "6.00 is 6.0001 and 6.0002"
new_str = ""
new_str += s[-1]
new_str += s[0]
new_str += s[4::30]
new_str += s[13:10:-1]
print(new_str)
A. 
B. 
C. 
D. 
Nothing, it will give an error
9.
How many times will the code below print "common letter"?
s1 = "mit u rock"
s2 = "i rule mit"
if len(s1) == len(s2):
for char1 in s1:
for char2 in s2:
if char1 == char2:
print("common letter")
break
A. 
B. 
C. 
D. 
10.
How many total lines of output will show up if you run the code below?
def add(x, y):
return x+y
def mult(x, y):
print(x*y)
add(1,2)
print(add(2,3))
mult(3,4)
print(mult(4,5))
A. 
B. 
C. 
D. 
11.
What does the code below print?
def sq(func, x):
y = x**2
return func(y)
def f(x):
return x**2
calc = sq(f, 2)
print(calc)
A. 
B. 
C. 
D. 
12.
Examine the code below. What does always_sunny(('cloudy'), ('cold',)) evaluate to?
def always_sunny(t1, t2):
""" t1, t2 are non empty """
sun = ("sunny","sun")
first = t1[0] + t2[0]
return (sun[0], first)
A. 
B. 
C. 
D. 
13.
What is the value of L after you run the code below?
L = ["life", "answer", 42, 0]
for thing in L:
if thing == 0:
L[thing] = "universe"
elif thing == 42:
L[1] = "everything"
A. 
["life", "answer", 42, 0]
B. 
["universe", "answer", 42, 0]
C. 
["universe", "everything", 42, 0]
D. 
["life", "everything", 42, 0]
14.
What is the value of L3 after you execute all the operations in the code below?
L1 = ['re']
L2 = ['mi']
L3 = ['do']
L4 = L1 + L2
L3.extend(L4)
L3.sort()
del(L3[0])
L3.append(['fa','la'])
A. 
['mi', 're', ['fa', 'la']]
B. 
C. 
['re', 'mi', ['fa', 'la']]
D. 
['do', 'mi', ['fa', 'la']]
15.
What is the value of brunch after you execute all the operations in the code below?
L1 = ["bacon", "eggs"]
L2 = ["toast", "jam"]
brunch = L1
L1.append("juice")
brunch.extend(L2)
A. 
['bacon', 'eggs', 'toast', 'jam']
B. 
['bacon', 'eggs', 'juice', 'toast', 'jam']
C. 
['bacon', 'eggs', 'juice', ['toast', 'jam']]
D. 
['bacon', 'eggs', ['toast', 'jam']]
16.
Which of the following is a good and valid definition for a class representing a car?
A. 
B. 
C. 
D. 
17.
Using the class definition below, which line creates a new Car object with 4 wheels and 2 doors?
class Car(object):
def __init__(self, w, d):
self.wheels = w
self.doors = d
self.color = ""
A. 
B. 
Mycar = Car(4, 2, "white")
C. 
D. 
18.
Which of the following methods changes the color of the car, based on the definition below?
class Car(object):
def __init__(self, w, d):
self.wheels = w
self.doors = d
self.color = ""
A. 
B. 
Def paint(self, c):
color = c
C. 
D. 
Def paint(self, c):
self.color = c
19.
You create a car with mycar = Car(4, 2). Which is a line of code to change the color of mycar to "red"?
class Car(object):
def __init__(self, w, d):
self.wheels = w
self.doors = d
self.color = ""
def paint(self, c):
self.color = c
A. 
B. 
C. 
D. 
20.
With the code below, what does the line print(mycar == yourcar) print?
class Car(object):
def __init__(self, w, d):
self.wheels = w
self.doors = d
self.color = ""
def paint(self, c):
self.color = c
def __eq__(self, other):
if self.wheels == other.wheels and \
self.color == other.color and \
self.doors == other.doors:
return True
else:
return False
mycar = Car(4, 2)
mycar.paint("red")
yourcar = Car(4,2)
print(mycar == yourcar)
A. 
B. 
C. 
D. 
21.
Which of the below is a getter method for the number of wheels?
class Car(object):
def __init__(self, w, d):
self.wheels = w
self.doors = d
self.color = ""
----------------------------------
(A) def get_wheels():
return wheels
(B) def get_wheels():
return self.wheels
(C) def get_wheels(self):
return wheels
(D) def get_wheels(self):
return self.wheels
A. 
B. 
C. 
D. 
22.
What line could replace ____blank____ to create a class that inherits from Animal in the code below?
____blank____
def speak(self):
print("ruff ruff")
d = Dog(7)
d.set_name("Ruffles")
d.speak()
A. 
B. 
C. 
D.