Page 19 - PYTHON-12
P. 19

Section B

                22.  Write the difference between append() and extend() functions of a list?                (2)
               Ans.  append() function adds a single item to the end of the list whereas extend() function adds one list at the end
                   of another list.
                    For example,

                   L1=[9,7,5]
                   L2=[12,78]
                   L1.append(90)

                   print(L1)
                   L1.extend(L2)
                   print(L1)
                23.  What are comments in Python? Which symbol is used to represent a comment?              (2)
               Ans.  Comments are additional information provided against a statement or a chunk of code for better clarity and
                   understanding of the code. Interpreter ignores them and does not count them in commands.
                    Hash symbol (#) or triple quotation marks (‘’’ or “””) are used to represent a comment.

                24.  Answer the following questions using built-in functions.                               (2)
                    If L1 = [5, 10, 15, 10, 5, 20, 10, 30, ...] and L2 = [100, 200, 300, ...], then
                    (I)  (A)  Write a statement to count the occurrences of 10 in L1.

                                                             OR
                        (B)  Write a statement to sort the elements of list L1 in descending order.

              Ans.  (I)  (A)  L1.count(10)
                                                             OR
                        (B)  L1.sort(reverse=True)
                   (II)  (A)  Write a statement to append all the elements of L2 to L1.

                                                             OR
                        (B)  Write a statement to reverse the elements of list L1.

              Ans.  (A)  L1.extend(L2)
                                                             OR
                   (B)  L1.reverse()

                25.  Identify the correct output(s) of the following code and write the minimum and maximum possible values of
                   the variable result.                                                                     (2)

                   import random
                   x1= random.randrange(1, 10, 2)

                   x2= random.randrange(1, 10, 3)
                   print (x1,"and",x2))
                   (a)  3 and 4
                   (b)  8 and 10
                   (c)  8 and 9
                   (d)  2 and 7

              Ans.  (a)  3 and 4


                                                                                Model Test Paper (Solved)   A.5
   14   15   16   17   18   19   20   21   22   23   24