CS 521 Final exam
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CS 521 Final exam
Q1. What is the output of the following program?
L1 = [1, 2, 3, 4]
L2 = L1
L3 = L1.copy()
L4 = list(L1)
L1[0] = [5]
print(L1, L2, L3, L4)
a. [5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
b. [[5], 2, 3, 4] [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4]
c. [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
d. [5, 2, 3, 4] [5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4]
Q2.
What is the result of print?
a = True; b = False; c = False
if a or b and c:
print ("Tea")
else:
print ("Coffee")
a Tea
Q3. What is the output of the following program?
for i in range(2)[::-1]:
print (i, end=’ ‘)
a 1 0
C
Q5.
What is the output of this code?
set1 = {1, 2, 3}
set2 = set1.copy()
set2.add(4)
print(set1)
a. {1, 2, 3, 4}
b. Error
c. Invalid Syntax
d. {1, 2, 3}
Q6.
What is the output of the following?
x=1; y=2; z=3
def FMA(x,y):
z=multiply(x,y)
x=x+z
return x
def multiply(x,y):
x=x*y
return x
z=FMA(1,1)
print (x,y,z)
a. 2 1 2
b. 2 4 1
c. 4 2 2
d. 1 2 2
Q7.
What is the output of the following program?
temp = dict()
temp['key1'] = {'key1' : 44, 'key2' : 566}
temp['key2'] = [1, 2, 3, 4]
for (key, values) in temp.items():
print(values, end = "")
a. Runtime error
b. None of the above
c. {‘key1’: 44, ‘key2’: 566}[1, 2, 3, 4]
d. Compilation error
Q8.
What is the output of the following?
data = [2, 3, 9]
temp = [[x for x in[data]] for x in range(3)]
print (temp)
a. [[2, 3, 9], [2, 3, 9], [2, 3, 9]]
b. [[[2, 3, 9]], [[2, 3, 9]], [[2, 3, 9]]]
c. None of these
d. [[[2, 3, 9]], [[2, 3, 9]]]
Q9.
What is the output of the following program?
L1 = []
L1.append([1, [2, 3, 4], 5])
L1.extend((7, 8, 9))
print(L1[0][1][1] + L1[2])
a. 12
b. 38
c. 11
d. TypeError: can only concatenate list (not “int”) to list
Q10.
What is the output of the following?
i = 1
while True:
if i % 5 == 0:
break
print(i, end=’ ‘)
i += 1
a. 1 2 3 4
b. error
c. 1 2 3 4 5
d. None of the above
Q11.
What is the output of the following?
def foo(x):
x = ['def', 'abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
a. None
b. True
c. Error
d. False
Q12.
What is the output of the following program?
T1 = (1)
T2 = (3, 4)
T1 += 5
print(T1)
print(T1 + T2)
a. 1 TypeError
b. TypeError
c. (1, 5, 3, 4)
d. 6 TypeError
Q13.
What is the output of the following:
i=0
def change(i):
i=i+1
return i
change(1)
print(i)
a. 0
b. nothing is displayed
c. an exception is thrown
d. 1
Q14.
What is the output of the following?
class Count:
def __init__(self, count=0):
self.__count=count
a=Count(2); b=Count(2); print(id(a)==id(b), end = ' ') c= 'hello'; d= 'hello'; print(id(c)==id(d))
a. True False
b. False True
c. True True
d. False False
Q15.
What is the result of the following?
line = "What will have so will"
L = line.split('a')
for i in L:
print(i, end=' ')
a. What will have so will
b. Wh t will h ve so will
c. [‘What’, ‘will’, ‘have’, ‘so’, ‘will’]
d. [‘Wh’, ‘t will h’, ‘ve so will’]
2023-12-14