Page 386 - Computer Science Class 11 With Functions
P. 386

Ans.  {1: 0, 2: 0, 3:0, 4: 0}
          6.  What will be the output produced on execution of the following sequence of steps, executed in IDLE:
              >>> myDict={ }
              >>> myDict[1] = {1:'One',2:'Two'}
              >>> myDict[2] = [1,2,3,4]
              >>> myDict
         Ans.  {1: {1: 'One', 2: 'Two'}, 2: [1, 2, 3, 4]}
           7.  What will be the output produced on execution of the following code snippet:
              >>> myDict = dict()
              >>> for k in range(5):
              ...     myDict[k+1] = (k+1)*(k+1)
              >>> myDict
         Ans.  {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
           8.  What will be the output produced on execution of the following code snippet:
              d1 = {1:11, 2:22}
              print(sum(d1), sum(d1.keys()), sum(d1.values()))
         Ans.  3 3 33
           9.  What will be the output produced on execution of the following code snippet:
              d = {1:'One',2:'Two'}
              print(d[1]+d[2])
         Ans.  OneTwo
          10.  What will be the output produced on execution of the following code snippet:
              d = {1:'One',2:'Two'}
              print(sum(d))
         Ans.  3
          11.  What will be the output produced on execution of the following code snippet:
              d = {'1':'one', '2':'two'}
              s = ''
              for x in d:
                  s = s + x
              print(s)
         Ans.  12
          12.  What will be the output produced on execution of the following code snippet:

              d = {'1':'one', '2':'two'}
              s = ''
              for x in d:
                  s = s + d[x]
              print(s)
         Ans.  onetwo
          13.  What will be the output produced on 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.


         384   Touchpad Computer Science-XI
   381   382   383   384   385   386   387   388   389   390   391