Page 384 - Computer Science Class 11 With Functions
P. 384
print(sumValues)
c. print(sum(myDict.keys()))
d. sumValues = 0
for key in myDict:
sumValues += myDict[key]
print(sumValues)
8. Which of the following is not a correct way to output the sum of the keys of the dictionary defined as follows:
>>> myDict = {1:"One",2:"Two",3:"Three"}
a. print(sum(myDict.keys()))
b. sumValues = 0
for value in myDict.keys():
sumValues += value
print(sumValues)
c. print(sum(myDict))
d. sumValues = 0
for key in myDict:
sumValues += myDict[key]
print(sumValues)
9. Consider the following dictionary:
>>> myDict = [1,2,{1:'One',2:{3:'Three',4:'Four',5:'Five'},6:'Six'},3,4]
Which of the following outputs 'Four' from myDict?
a. myDict[2][1][1]
b. myDict[2][2][4]
c. myDict[1][2][4]
d. myDict[1][1][1]
10. What will be the output produced on execution of the following code snippet?
s = ''
d = {'1':'One','2':'Two'}
for k,v in d.items():
s = k + v
print(s)
a. An error would occur
b. 1One2Two
c. 2Two
d. 1One
B. State whether the following statements are True or False:
1. A dictionary is a sequence of objects over which we can iterate in a for statement. _________
2. Dictionaries are immutable. _________
3. All the keys in a dictionary must be of the same type. _________
4. A key in a dictionary can not be a mutable data type. ` _________
5. If d is a dictionary, d[0] will yield its first key. _________
6. If d is a dictionary, d[0] will yield an error because a dict object is not subscriptable. _________
7. If d is a dictionary, d.keys()[0] will yield its first key. _________
382 Touchpad Computer Science-XI

