1.
What gets printed (with python version 3.X) assuming the user enters the following at the prompt?
#: foo
a = input("#: ")
print a
A. 
B. 
C. 
D. 
2.
What gets printed?
class NumFactory:
def __init__(self, n):
self.val = n
def timesTwo(self):
self.val *= 2
def plusTwo(self):
self.val += 2
f = NumFactory(2)
for m in dir(f):
mthd = getattr(f,m)
if callable(mthd):
mthd()
print f.val
A. 
B. 
C. 
D. 
E. 
3.
What gets printed?
def print_header(str):
print "+++%s+++" % str
print_header.category = 1
print_header.text = "some info"
print_header("%d %s" % \
(print_header.category, print_header.text))
A. 
B. 
C. 
D. 
4.
What gets printed?
names1 = ['Amir', 'Barry', 'Chales', 'Dao']
names2 = [name.lower() for name in names1]
print names2[2][0]
A. 
B. 
C. 
D. 
E. 
5.
What gets printed?
names1 = ['Amir', 'Barry', 'Chales', 'Dao']
loc = names1.index("Edward")
print loc
A. 
B. 
C. 
D. 
E. 
6.
Assuming the filename for the code below is /usr/lib/python/person.py
and the program is run as:
python /usr/lib/python/person.py
What gets printed?
class Person:
def __init__(self):
pass
def getAge(self):
print __name__
p = Person()
p.getAge()
A. 
B. 
C. 
D. 
E. 
7.
What gets printed?
import re
sum = 0
pattern = 'back'
if re.match(pattern, 'backup.txt'):
sum += 1
if re.match(pattern, 'text.back'):
sum += 2
if re.search(pattern, 'backup.txt'):
sum += 4
if re.search(pattern, 'text.back'):
sum += 8
print sum
A. 
B. 
C. 
D. 
E. 
8.
What numbers get printed
import pickle
class account:
def __init__(self, id, balance):
self.id = id
self.balance = balance
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
self.balance -= amount
myac = account('123', 100)
myac.deposit(800)
myac.withdraw(500)
fd = open( "archive", "w" )
pickle.dump( myac, fd)
fd.close()
myac.deposit(200)
print myac.balance
fd = open( "archive", "r" )
myac = pickle.load( fd )
fd.close()
print myac.balance
A. 
B. 
C. 
D. 
E. 
9.
What gets printed?
class parent:
def __init__(self, param):
self.v1 = param
class child(parent):
def __init__(self, param):
self.v2 = param
obj = child(11)
print "%d %d" % (obj.v1, obj.v2)
A. 
B. 
C. 
D. 
E. 
Error is generated by program
10.
The following code will successfully print the days and then the months
daysOfWeek = ['Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday']
months = ['Jan', \
'Feb', \
'Mar', \
'Apr', \
'May', \
'Jun', \
'Jul', \
'Aug', \
'Sep', \
'Oct', \
'Nov', \
'Dec']
print "DAYS: %s, MONTHS %s" %
(daysOfWeek, months)
11.
What gets printed?
x = True
y = False
z = False
if not x or y:
print 1
elif not x or not y and z:
print 2
elif not x or y or not y and x:
print 3
else:
print 4
A. 
B. 
C. 
D. 
12.
In python 2.6 or earlier, the code will print error type 1 if accessSecureSystem raises an exception of either AccessError type or SecurityError type
try:
accessSecureSystem()
except AccessError, SecurityError:
print "error type 1"
continueWork()
13.
What gets printed?
kvps = {"user","bill", "password","hillary"}
print kvps['password']
A. 
B. 
C. 
D. 
E. 
Nothing. Python syntax error
14.
What gets printed?
def simpleFunction():
"This is a cool simple function that returns 1"
return 1
print simpleFunction.__doc__[10:14]
A. 
B. 
C. 
D. 
E. 
15.
What gets printed?
import re
sum = 0
pattern = 'back'
if re.match(pattern, 'backup.txt'):
sum += 1
if re.match(pattern, 'text.back'):
sum += 2
if re.search(pattern, 'backup.txt'):
sum += 4
if re.search(pattern, 'text.back'):
sum += 8
print sum
A. 
B. 
C. 
D. 
E.