Page 205 - Information_Practice_Fliipbook_Class11
P. 205

4.  Consider  the following statements and  select  the correct  output  that will  be produced  when they are executed in a
                  sequence:
                  numbers = [3, 10, 5, 15, 20, 34, 8, 5]
                  numbers[4:8:2] * 2
                  a.  [20, 8]              b. [20, 8, 20, 8]      c. Error              d. []

               5.  Consider the following list:
                      names = ['jaipur', 'nagpur', 'pune', 'shimla']
                  Which of the following statements will insert the string, 'agra' as the third element of the list?

                  a.  names.insert(2, 'agra')
                  b.  names.insert(3, 'agra')
                  c.  names.extend(2, 'agra')
                  d.  names.extend(3, 'agra')
               6.  Consider the following list:
                      names = ['jaipur','nagpur', 'pune', 'shimla']
                  Which of the following statements will delete the string 'pune' from the list?
                  a.  names.pop()
                  b.  names.pop(3)
                  c.  names.remove('pune')
                  d.  names.remove(2)
            B.  State whether the following statements are True or False:
               1.  We can replace an item in a list with another item.                                      ________
               2.  pop() and remove() are similar functions, they take the element to be deleted from the list as arguments.   ________
               3.  The element at a given position in a list can be changed using the assignment statement.    ________
               4.  The elements of the list can be repeated a specified number of times using the * operator.    ________
            C.  Fill in the blanks.
               1.  A list comprises a comma-separated sequence of objects enclosed in ____________.
               2.  The function ____________ converts a string into a list.
               3.  The slice lst[:3] yields the list comprising of first ____________ elements of list lst.
               4.  The function ____________returns a sorted list comprising the elements of the list passed as an argument, but without
               5.  ____________ is the concatenation operator.

            D.  Answer the following questions:
               1.  Write a program to find the largest element of a list, without using the functions max(), min(), and sorted().
               2.  What will be the output produced on the execution of the following code?
                  myList = [1, 0, -1]
                  newList = myList * 3
                  newList.insert(-1, 5)
                  indx = newList.index(5)
                  print(indx)
               3.  Write a program that accepts a list of numbers from a user and interchanges the elements at indices 0, 2, 4 , … with those
                  at indices 1, 3, 5, … respectively. The program should display the resulting list. Assume that the number of elements
                  in the list is even.
               4.  Write a program that accepts a list of numbers from a user and interchanges the elements at indices 0, 2, 4, … with those
                  at indices 1, 3, 5, … respectively. The program should display the resulting list. If there is no matching index for the last
                  element of the list, retain the element as it is.





                                                                                                   Python Lists  191
   200   201   202   203   204   205   206   207   208   209   210