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

7.  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')
           8.  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)
           9.  What will be the output produced if the following code is executed?
              tup = (1, 2, 3, 4, 5)
              mySum = sum(tup, 10)
              print(mysum)
              a.  15                   b. 25                  c. Error               d. No output
          10.  Consider the following statement:
              myTup = (10, -4, 0, 3, -1, 6)
              Which of the following statements will display the tuple, sorted in descending order?

              a.  tuple(sorted(myTup)
              b.  tuple(sorted(myTup, reverse=False))
              c.  tuple(sorted(myTup, desc))
              d.  tuple(sorted(myTup, reverse=True))
        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 that 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 function sort() can be used to arrange the elements of the tuple in ascending order.
           5.  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
              modifying the original list.
           5.  ________ is the concatenation operator.
        D.  Answer the following questions:
           1.  Write a function maxList() to find the largest element of a list, without using the functions max(), min(), and
              sorted(). Write  program that accepts a list from a user, and finds the maximum element in the list using the function
              maxList() and  displays the maximum element in the list.





         364   Touchpad Computer Science-XI
   361   362   363   364   365   366   367   368   369   370   371