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

5.  Which of the following can be the possible output produced on the execution of the following code snippet?
                    colours = {"red", "green", "blue", "Yellow"}
                    code = 0
                    cDict = {}
                    print( cDict.fromkeys(colours, code) )
                    a.  {'Yellow': '0', 'red': '1', 'blue': '2', 'green': '3'}
                    b.  {'Yellow': 0, 'red': 0, 'blue': 0, 'green': 0}
                    c.  {'Yellow': 1, 'red': 2, 'blue': 3, 'green': 4}
                    d.  Error

                 6.  Consider the following dictionary:
                    subjects = {101:'English', 102:'Hindi', 103:'Maths'}
                    Which of the following pairs of expressions will yield the same output?

                    a.  subjects.get('102') and subjects[102]
                    b.  subjects.popItem(102) and subjects[102]
                    c.  subjects.values() and subjects.items()
                    d.  subjects[102] and subjects.get(102)
                 7.   Which of the given statements will add a new key value pair to the dictionary d1 given below:
                    d1 = {"Netflix":300,  "Prime":250, "Sony Liv": 100}
                    a.  d1["Prime"]=190
                    b.  d1["Disney Hotstar"]=175
                    c.  abc=d1.get("Netflix")
                    d.  d1.update({"Sony Liv":280})
                 8.  Consider  the following dictionary:
                    ticketPrice = {'Chandigarh':450,  'Nagpur':760,  'Pune':380}
                    What will be the output of the statement,  min(ticketPrice)?

                    a.  450                  b. Chandigarh          c. Pune               d. 380
                 9.  What will be the output produced on executing  the following code segment?

                    d = {1:'a', 2:'b', 3:'c'}
                    sum(d)
                    a.  Error, as aggregate functions do not apply on dictionary
                    b.  6.0
                    c.  abc
                    d.  6
                10.  Which of the following functions will add a key to a dictionary only if it does not already exist in the dictionary?
                    a.  update()             b. get()               c. setdefault()       d. fromkeys()
                11.  Which of the following can be used to add to dictionary, all key-value pairs of another dictionary in an existing dictionary?
                    a.  update()             b. get()               c. setdefault()       d. fromkeys()
              B.  State whether the following statements are True or False:

                 1.  A dictionary can have two different keys with same value.                                 ________
                 2.  A tuple can be used as key in a dictionary.                                               ________
                 3.  The value associated with a key in a  key-value pair of a dictionary cannot be modified.    ________
                 4.  Given a dictionary, its values can be accessed using keys as indexes.                     ________
                 5.  The method sorted() is used to sort the keys of a dictionary in ascending or descending order.   ________




               428   Touchpad Computer Science (Ver. 2.0)-XI
   437   438   439   440   441   442   443   444   445   446   447