Page 435 - Computer Science V2.0 Class 11
P. 435

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]
                         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)



                                                                                                        Dictionaries  421
   430   431   432   433   434   435   436   437   438   439   440