COMP SCI FINAL
What is the value of sys.argv, len(sys.argv) for the command-line input> python prog.py 1 January 2020? A. ['1', 'January', '2020'], 3 B. ['prog.py', '1', 'January', '2020'], 4 C. ['prog.py', '1', 'January', '2020'], 3 D. ['1', 'January', '2020'], 1
B. ['prog.py', '1', 'January', '2020'], 4
What is output? b1 = [7, 5, 9, 6] b1.sort() b2 = b1.copy() b1.append(10) b2 = b2[::-1] print(b1, b2) [5, 6, 7, 9, 10] [10, 9, 7, 6, 5] [5, 6, 7, 9, 10] [5, 6, 7, 9, 10] [5, 6, 7, 9, 10] [9, 7, 6, 5] [5, 6, 7, 9, 10] [5, 6, 7, 9]
[5, 6, 7, 9, 10] [9, 7, 6, 5]
How many times will the print statement execute? for i in range(1, 3): for j in range(8, 12, 2): print(f'{i}. {j}') a) 4 b) 6 c) 9 d) 36
a) 4
Which operator is evaluated last in an expression? a) or b) and c) == d) +
a) or
Which of the following statements correctly opens a file in append mode without the need for specifying a close() function for the file? a) with open('my_list.txt', 'a+') as file: b) file = with open('my_list.txt', 'a+') c) with open('my_list.txt', 'rb') as file: d) file = with open('my_list.txt', a)
a) with open('my_list.txt', 'a+') as file:
A(n) _____ is a directory that gives access to all of the modules stored in a directory when imported. a) function b) package c) init d) group
b) package
Which is true of the badly formatted code? x = input() if x == 'a': print('first') print('second') a) Both print() statements must be indented. b) Neither print() statement has to be indented. c) The first print() statement must be indented. d) The second print() statement must be indented.
c) The first print() statement must be indented.
Which statement is true regarding the pop() method for sets? a) pop() removes the first item added to the set. b) pop() removes the last item added to the set. c) pop() removes a random item in the set. d) pop() returns but does not remove a random item in the set.
c) pop() removes a random item in the set
How many times will the print statement execute? for i in range(10): for j in range(3): print(f'{i}. {j}') a) 3 b) 10 c) 13 d) 30
d) 30
Which XXX / ZZZ outputs every name/grade pair in the dictionary, as in: Jennifer: A? grades = {'Jennifer' : 'A','Ximin' : 'C','Julio' : 'B','Jason' : 'C'} for XXX: print(ZZZ) name in grades / name + ': ' + grade grade in grades / name[grades] + ': ' + grade name in names / grades[name] + ': ' + grades[grade] name in grades / name + ': ' + grades[name]
name in grades / name + ': ' + grades[name]
Select the code that gives ['cat in a hat', 'fluffy dogs', 1989, 1990] as the output. a) new_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffy dogs']print(new_list[-2:] + [1989, 1990]) b) new_list = ['cat in a hat', 'fluffy dogs','1000', '2000', '3000']print(new_list[-2:] + [1989, 1990]) c) new_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffy dogs']print(new_list[-1:] + [1989, 1990]) d) new_list = ['1000', '2000', '3000', 1989, 1990]print(new_list[-2:] + ['cat in a hat', 'fluffy dogs'])
new_list = ['cat in a hat', 'fluffy dogs','1000', '2000', '3000']print(new_list[-2:] + [1989, 1990])
Identify the code used for matrix multiplication of two arrays. a) np.mat(array1, array2) b) np.dot(array1, array2) c) np.malmul(array1, array2) d) np.cross(array1, array2)
np.dot(array1, array2)
Which package provides tools for scientific and mathematical computations in Python? pandas numpy sklearn matplotlib
numpy
What is output? dict1 = {1: 'Hi', 2: 'Bye'} dict2 = {2: 'Yes'} dict1.update(dict2) dict3 = {3: 'No'} dict1.update(dict3) print(dict1) {1: 'Hi', 2: 'Bye', 2: 'Yes', 3: 'No'} {1: 'Hi', 2: 'Yes', 3: 'No'} {1: 'Hi', 2: 'ByeYes', 3: 'No'} {1: 'Hi', 2: 'Yes', 2: 'Bye', 3: 'No'}
{1: 'Hi', 2: 'Yes', 3: 'No'}
What is the output? num_list = [ 3, 8, 5, 15, 12, 32, 45 ] for index, value in enumerate(num_list): if index > 0: if value < num_list[index-1]: print('*', end='') print(value, end=' ') a) 3 8 5 15 12 32 45 b) *3 8 5 15 12 32 45 c) *3 *8 5 *15 12 *32 *45 d) 3 8 *5 15 *12 32 45
d) 3 8 *5 15 *12 32 45
Which of the following statements removes the value 'Google' from the set, companies? companies = { 'Apple', 'Microsoft', 'Google', 'Amazon' } a) companies.pop(2) b) companies.pop('Google') c) companies.remove(2) d) companies.remove('Google')
d) companies.remove('Google')
Identify the code that generates 'The value of pi is: 3.14' as output. import pi from math print(f'The value of pi is: {pi:.2f}') from math import pi print(f'The value of pi is: {pi:.2f}') import pi from math print(f'The value of pi is: {pi:.2f}') import math print(f'The value of pi is: {pi:.2f}') import pi print(f'The value of pi is: {math.pi:.2f}')
from math import pi print(f'The value of pi is: {pi:.2f}')