Title | CS1101 Unit 7 Quiz |
---|---|
Course | Programming Fundamentals |
Institution | University of the People |
Pages | 5 |
File Size | 113.8 KB |
File Type | |
Total Downloads | 37 |
Total Views | 160 |
Download CS1101 Unit 7 Quiz PDF
Self-quiz 7 review Question 1 What is the output of the following Python program? print(dict().get("no", "help!")) Select one: a. b. c. d. e.
True No No help! Help! False
The correct answer is: help!
Question 2 If you use a Python dictionary in a for statement, it traverses the _____ of the dictionary. Select one: a. b. c. d. e.
values and keys indices keys and values values keys
Select one: The correct answer is: keys
Question 3 Given a Python dictionary d and a value v, it is efficient to find the corresponding key: d[k] = v. Select one: True False The correct answer is: ‘False’
Question 4 What will the contents of mylist be after the following Python code has been executed? >>> mylist = [1, 4, 2, 3] >>> mylist.append(5) Select one: a. [1, 4, 2, 3, 5]
b. [5, 1, 4, 2, 3] c. [null] d. [1, 4, 2, 3] The correct answer is: [1, 4, 2, 3, 5]
Question 5 What is the output of the Python code below? my_list = [3, 2, 1] print(my_list.sort()) Select one: a. b. c. d. e.
0 {1, 2, 3} None Syntax error [1, 2, 3]
The correct answer is: None
Question 6 Python functions can take a variable number of arguments. Select one: True False The correct answer is: ‘True’
Question 7 Python dictionaries are mutable. Select one: True False The correct answer is: ‘True’
Question 8 What is the value of the following Python expression? (0, 1, 5, 2) > (0, 1.0, 4, 3.1) Select one: a. b. c. d.
0 1 False True
e. Syntax error The correct answer is: True
Question 9 Assume that d is a Python dictionary. What does the following Python code produce? or k in d: if d[k] == v: return k Select one: a. b. c. d. e.
a histogram an inverted dictionary a list of tuples a lookup a reverse lookup
The correct answer is: a reverse lookup
Question 10 In the following segment of Python code, what do we call the portion of the statement that follows the dot('.capitalize')? str.capitalize('maryland') Select one: a. b. c. d.
Module Method Attribute Function name
The correct answer is: Method
Question 11 Which of the following types are allowed for Python dictionary keys? Select one: dictionary list list of dictionaries tuple All of the above The correct answer is: tuple
Question 12 Which of the following types are allowed for Python dictionary values? Select one: a. b. c. d. e.
dictionary list list of dictionaries tuple All of the above
The correct answer is: All of the above
Question 13 What is the output of the Python code below? my_tup = (3, 2, 1, 2) print(tuple(sorted(my_tup))) Select one: a. b. c. d. e.
(1, 2, 3) {1, 2, 2, 3} (1, 2, 2, 3) syntax error [1, 2, 2, 3]
The correct answer is: (1, 2, 2, 3)
Question 14 Assume that d is a Python dictionary. What does the following Python code produce? d.items() Select one: a. b. c. d. e.
a histogram an inverted dictionary a list of tuples a lookup a reverse lookup
The correct answer is: a list of tuples
Question 15 Assume that d is a Python dictionary. What does the following Python code produce? d.items() Select one: a. a histogram
b. c. d. e.
an inverted dictionary a list of tuples a lookup a reverse lookup
The correct answer is: an inverted dictionary
Question 16 Python tuples are immutable. Select one: True False The correct answer is: ‘True’...