Page 5 - PYTHON-12
P. 5

6.  What will be the output of the following code?                                             (1)

               t1 = (1, 2, 3)
               t2 = (4, 5)
               result = t1 * 2 + t2
               print(result)
                (a)  (1, 2, 3, 1, 2, 3) + (4, 5)          (b)  (1, 2, 3, 4, 5)
                (c)  (2, 4, 6, 8, 10)                     (d)  (1, 2, 3, 1, 2, 3, 4, 5)
           Ans.  (d)  (1, 2, 3, 1, 2, 3, 4, 5)
            7.  If car_info is a dictionary as defined below, then which of the following statements will raise an
               exception?                                                                                  (1)
               car_info = {'make': 'Toyota', 'model': 'Corolla', 'year': 2020}
                (a)  car_info['model'] = 'Camry'          (b)  car_info['year'] = 2021
                (c)  print(car_info.get('make'))          (d)  print(car_info['color'])
           Ans.  (d)  print(car_info['color'])
            8.  Which of the following statements accurately describes the behaviour of the update() method when used
               with dictionaries in Python?                                                                (1)
                (a)  It creates a new dictionary by merging the original dictionary with another dictionary or iterable and
                   returns this new dictionary.
                (b)  It replaces the values of the keys that already exist in the dictionary with the values from another
                   dictionary or iterable and adds new key-value pairs if they do not exist in the original dictionary.
                (c)  It only adds new key-value pairs from another dictionary or iterable to the original dictionary without
                   modifying any existing key-value pairs.
                (d)  It removes key-value pairs from the original dictionary that are present in another dictionary or iterable.
           Ans.  (b)  It replaces the values of the keys that already exist in the dictionary with the values from another
                   dictionary or iterable and adds new key-value pairs if they do not exist in the original dictionary.
            9.  If a table has three candidate keys and two alternate keys, then how many primary keys will this table
               have?                                                                                       (1)
           Ans.  A table has only one primary key.
            10.  Write the missing statement to complete the following code:                               (1)
               file = open("records.txt", "r")
               content = file.read()
               _________________ # Move the file pointer to the beginning of the file
               firstline = file.readline()
               file.close()
           Ans.  file.seek(0)
            11.  State whether the following statement is True or False:                                   (1)
               IOError is raised in Python when an index is not found in a sequence, i.e., it is out of range or out of bounds.
           Ans.  False
            12.  What will be the output of the following code?                                            (1)
               z = 30
               def cal():
                     z = 60
                     print(z, end="#")
               cal()
               z = z + 10
               print(z, end="@")
                (a)  60#70@                               (b)  60#30@
                (c)  60#40@                               (d)  60@40#
           Ans.  (c)  60#40@
            13.  Which SQL command is used to add a primary key constraint to an existing table?           (1)
           Ans.  ALTER TABLE command is used to add a primary key constraint to an existing table.

          A.36                                                           Computer Science with Python–XII
   1   2   3   4   5   6   7   8   9   10