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

11.  Will the following code execute successfully? If yes, what will be the output produced on execution of the code? If not,
                  what is the error in the code?
                  myList = [1, 0, -1]
                  newList = myList * 3
                  newList.insert(-1, 5)
                  value = newList.index(4)
                  print(value)
             Ans.  No, the code will not execute successfully as 4 is not present in the list newList, so index() will result in an error.

              12.  What will be the output produced on execution of the following code?
                 data =['WHAT', 1, 'IS', 2, 'THIS', 3, 'PLEASE', 4]
                 alpha = ''
                 beta = 0
                 for c in range(1, 7, 2):
                     beta = beta + c
                     alpha = alpha + data[c-1] + '!!'
                     beta = beta + data[c]
                 print(alpha, beta, sep='#')
             Ans.  WHAT!!IS!!THIS!!#15


                   Assertion and Reasoning Based Questions


                  The following questions are assertion(A) and reasoning(R) based. Mark the correct choice as
                  a.  Both A and R are true and R is the correct explanation of A
                  b.  Both A and R are true and R is not the correct explanation of A
                  c.  A is true but R is false
                  d.  A is false but R is true

               1.  Assertion(A):  A list assignment does not create a new copy of the list.
                  Reasoning (R):  List is a mutable data type.

               2.  Assertion(A):  '+' is an operator that can be used to concatenate a pair of lists.
                  Reasoning(R):  + is a generic operator for concatenating lists, strings, and tuples..
               3.  Assertion(A):  The method extend() can insert elements at any position in the list.
                  Reasoning(R):  extend() only takes an iterable sequence as an argument.
             Ans.  1. a  2. a  3. d


                  Case Based Questions



               1.  Avantika is a fashion designer and has to present her designs at an upcoming exhibition. She wants to maintain a fixed list
                  of categories of clothing that she would like to exhibit. These categories are:
                  ●  Wedding collection (wedding)
                  ●  Casual Wear (casual)
                  ●  Party Wear (party)
                  ●  Sports Wear (sports)
                  Avantika wants to be able to enter the type of clothing for several pieces of clothing and finally see on the screen the
                  number of clothing items in each category. As a software developer, help her do this job. If a clothing item is not from one
                  of the mentioned categories, then an appropriate error message should be displayed.



                                                                                                Lists and Tuples  359
   356   357   358   359   360   361   362   363   364   365   366