Page 383 - Computer Science Class 11 With Functions
P. 383
Solved Exercise
A. Multiple Choice Questions
1. Which of the following statements will delete a key-value pair for the key 'tue' in the following dictionary?
days = {'sun':1,'mon':2,'tue':3,'wed':4,'thur':5}
a. delete days['tue']
b. del.days['tue']
c. del days['tue']
d. days.del['tue']
2. Which of the following will display the keys in the dictionary myDict?
a. myDict.keys()
b. keys(myDict)
c. myDict.key()
d. print(myDict.key())
3. Consider the following dictionary:
numSquares = {1:1, 2:4, 3:9, 4:16, 5:25}
Which of the following will delete the key:value pair 2:4
a. del numSquares[2:4]
b. del numSquares[2]
c. numSquares.remove(2)
d. numSquares.remove(2:4)
4. Which of the following will remove all the elements of the dictionary numSquares, but not delete the dictionary object
itself.
a. clear numSquares
b. del numSquares
c. numSquares.clear()
d. clear(numSquares)
5. Which of the following will display the number of key value pairs in the dictionary myDict?
a. myDict.len()
b. len(myDict)
c. myDict.size()
d. size(myDict)
6. What will be the output produced on execution of the following code snippet?
myDict = [1,2,{1:'One',2:{3:'Three',4:'Four',5:'Five'},6:'Six'},3,4]
print(5 in myDict,3 in myDict)
a. True False
b. True True
c. False True
d. False False
7. Which of the following is not a correct way to output the sum of the values of the dictionary defined as follows:
>>> myDict = {"One":1,"Two":2,"Three":3}
a. print(sum(myDict.values()))
b. sumValues = 0
for key in myDict.keys():
sumValues += myDict[key]
Dictionaries 381

