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

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.   ________
            C.  Fill in the blanks.
               1.  The elements of a dictionary are  enclosed in _________ brackets.
               2.  Every item in the dictionary must have a unique _________ with its corresponding value.
               3.  To delete a key-value pair from a dictionary, _________ statement is used.
               4.  The function _________ is used to create an empty dictionary.
               5.  The _________ method returns a new copy of the dictionary.
            D.  Answer the following questions:
               1.  What is a dictionary in Python? Illustrate with the help of an example.
               2.  Is slicing applicable to dictionaries? Justify your answer.
               3.  Which type of objects can be used as keys in dictionaries?
               4.  Give any two ways of creating an empty dictionary.
               5.  Why is a dictionary termed as an unordered collection of key: value pairs?
               6.  Given a dictionary with key value pairs to be Roll no and marks of the student as follows:

                  rollnoMarks = {1:60,2:25,3:90,4:32,5:12,6:78}
                  Write a code segment to get the roll nos of the students securing 40 marks or above.
               7.  Write a function charCountDict(string) to find the number of occurrences of each character in a given string in the
                  form of a dictionary. Apply the function charCountDict(string) to a list entered by the user.
               8.  Write a program that accepts from a user the number of students in a class, followed by the names and marks of the
                  students in the class, stores them  in a dictionary as key-value pairs, and displays the name of the student who has scored
                  maximum marks.
               9.  Write a program to do the following:
                  • Create a dictionary of month names and the number of days in a month.
                  • Displays the names of months having 31 days.




                                                                                                   Dictionaries  389
   386   387   388   389   390   391   392   393   394   395   396