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

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.                              _________

              C.  Fill in the blanks.
                 1.  The expression print(len({1: 2, 2: 3, 1:2})) yields ______________.
                 2.  Consider a dictionary:
                    myDict = {1:{2},  2: {3:  5}}
                    The expression 3 in myDict yields ______________.
                 3.  While working in IDLE environment, a dictionary rollnoMarks   of key value pairs rollNo: marks has just been
                    created:
                     >>> rollnoMarks = {1:60,2:25,3:90,4:32,5:12,6:78}
                    The function call _________ will yield the marks for the candidate with rollNo  4 and remove the pair  4:32  from
                    rollnoMarks.
                 4.  Consider  the  dictionary  given  in  Ques  3.  The  expression  print(sorted(rollnoMarks.values())) yields
                    _______________.
                 5.  Consider a dictionary having the student details as follows:

                    studentDetails = {'Name':'Varun','Roll No': 5,'Marks':90}
                    The expression print(studentDetails.get('Roll No')) yields ______________ .
                 6.  Consider the same dictionary given in Ques. 5, the expression print(studentDetails.get('Roll Number'))
                    yields ______________ .




               422   Touchpad Computer Science (Ver. 2.0)-XI
   431   432   433   434   435   436   437   438   439   440   441