CSC 111 Quiz 6, Fall 2006

Submit by Tues December 12 by midnight


Name: First name :
Last name  :
Account name for copy (e.g., 111a-xx):
  
Quiz Code (password):

(Please take this quiz just once, unless you are told that the username or code is incorrect.
Write your quiz answers on paper before you hit the Submit Button,
in case you enter the wrong quiz password.)

1. Consider the python statements below:
doubleList = []
for i in range(4): 
    doubleList.append(i*2)
print doubleList
What is printed?
[]
[0, 1, 2, 3]
[doubleList]
[0, 2, 4, 6]
none of the above.
2. Consider the python statement below:
x = [[4,5,3], [3,6,5], [12,7,16]]
How do we retrieve the value 16?
x[2,2]
x[2][2]
x[2]
None of the above.
True or False?
A byte is 16 bits.
True
False
4. Consider the function definition:
def test(num):
    if num < 11:
        print num
    else:
        print 11
What is num?
11
a formal parameter
local.num
an actual parameter
5. True or False:
Recursive function definitions are not allowed in python
True
False
6. Consider the python statements
x = [2,4,5]
print x[:-1]
What is printed?
5
[5]
[2,4,5]
[2,4]
7. True or False
A program can write another program to a file.
True
False
8. Consider the following python statements:
def main():
    x = 4
    print x
    x = x + 1
What is the value of variable x when x is printed?
4
5
1
none of the above
9. Suppose I have the following:
z = "two"
print len(z)
What is printed?
2
3
4
10. Consider the following python code:
class Nuance:
    def __init__(self, x):
        self.x = x
    def getX(self):
        return self.x
def main():
    mylist = []
    for i in range(6):
        if i % 2 == 0:
	    newObj = Nuance(i)
	    mylist.append(newObj)
    for i in mylist:
        print i.getX(),
What is printed?
0 1 2 3 4 5
0 1 2
0 2 4
0 2 4 6

To submit:

Press to submit your fully-completed quiz, or to reset all fields. Thanks!