Page 223 - Information_Practice_Fliipbook_Class11
P. 223

12.  What will be the output produced on the execution of the following code snippet (executed in IDLE)?
                 d = {'1':'one', '2':'two'}
                 s = ''
                 for x in d:
                     s = s + x

                 print(s)
             Ans.  12
              13.  What will be the output produced on the execution of the following code snippet?
                 d = {'1':'one', '2':'two'}
                 s = ''
                 for x in d:
                     s = s + d[x]
                 print(s)
             Ans.  onetwo
              14.  What will be the output produced on the execution of the following code snippet?
                 d = {'1':'One','2':'Two'}
                 for k,v in d.items():
                     print(type(k,v))
             Ans.  An error would occur as k and v are considered two independent objects.
              15.  What will be the output produced on the execution of the following code snippet?
                 d = {'1':'One','2':'Two'}
                 for k,v in d.items():
                     z = k,v
                     print(type(z))
             Ans.  <class 'tuple'>
                  <class 'tuple'>


                   Assertion and Reasoning Based Questions


               The following questions are assertion(A) and reasoning(R) based. Mark the correct choice as
               a.  Both A and R are true and R is the correct explanation of A
               b.  Both A and R are true and R is not the correct explanation of A
               c.  A is true but R is false
               d.  A is false but R is true

               1.  Assertion(A):  The method pop() deletes the last key-value pair from a  dictionary.
                 Reasoning (R):  The method popitem() deletes a key-value pair from a dictionary.

               2.  Assertion(A):  Dictionary is a mutable data type.
                 Reasoning (R):  The keys in a dictionary are required to be unique.
             Ans.  1. d 2. b



                  Case-based Questions

               1.  On the occasion of an interschool festival, Ruhaan has been assigned the task of maintaining the points tally. As he just
                  learnt about dictionaries, he wants to develop a program that will accept from a user the following data about the events
                  in which a school participates:


                                                                                             Python Dictionaries  209
   218   219   220   221   222   223   224   225   226   227   228