Page 222 - Information_Practice_Fliipbook_Class11
P. 222

4.  What will be the output produced on the execution of the following code snippet?

              myDict = {}
              val = 0
              myDict.fromkeys([1,2,3,4],'val')
              print(myDict)
         Ans.  {}
           5.  What will be the output produced on the execution of the following code snippet?

              myDict = {}
              val = 0
              d = myDict.fromkeys([1,2,3,4],val)
              print(d)
         Ans.  {1: 0, 2: 0, 3:0, 4: 0}

           6.  What will be the output produced on the execution of the following statements, executed in Python IDLE?
              myDict[1] = {1:'One',2:'Two'}
              myDict[2] = [1,2,3,4]
              print(myDict)
         Ans. {1: {1: 'One', 2: 'Two'}, 2: [1, 2, 3, 4]}
           7.  What will be the output produced on the 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 the 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 the 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 the execution of the following code snippet?

              d = {1:'One',2:'Two'}
              print(sum(d))
         Ans.  3
          11.  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 + x
              print(s)
         Ans.  12



          208  Touchpad Informatics Practices-XI
   217   218   219   220   221   222   223   224   225   226   227