Page 417 - Computer Science V2.0 Class 11
P. 417

2.  Write a function minList() to find the smallest element of a tuple, without using the functions max(), min(),
                      and sorted(). Write program that accepts a tuple from a user, and finds the minimum element in the tuple using the
                      function minList() and  displays the minimum element in the list.
                    3.  Write a function that accepts as input date as an integer whose digits signify DDMMYYYY from left to right and returns a
                      tuple of numbers having the values  (DD, MM, YYYY). Use this function in a program to display the output in the following
                      format:

                      Day  : DD
                      Month: MM
                      Year : YYYY
                    4.  Write a function that accepts an integer n as the argument and returns a tuple comprising the first n elements of the
                      Fibonacci sequence:
                      1, 1, 2, 3, 5, 8, 13, 21, 34, ….
                    5.  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)
                    6.  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 resulted list. Assume that the number of elements
                      in the list is even.
                    7.  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 resulted list. If there is no matching index for the last
                      element of the list, retain the element as it is.
                    8.  Write a program that
                      a. accepts  a tuple (say, tpl) of numbers from a user.
                      b. construct a tuple (say, sqrTuple) as follows:
                          i.  The elements at odd indexes are same as those at odd indexes in the tuple tpl.
                         ii.  The elements at even indexes are computed  according to the formula: n**2, where n is the index of the element.
                      if the user enters the tuple:

                      (20, 5, 2, 8, 23, 26, 54, 83, 23, 99)
                      the program should display the tuple:
                      (0, 5, 4, 8, 16, 26, 36, 83, 64, 99)
                    9.  Write a program that
                       a. accepts  a tuple (say, tpl) of numbers from a user
                       b. construct a list (say, sqrList) as follows:
                          i.  The elements at odd indexes are same as those at odd indexes in the tuple tpl.
                          ii.  The elements at even indexes are computed  according to the formula: n**2, where n is the index of the element.
                      if the user enters the tuple:
                      (20, 5, 2, 8, 23, 26, 54, 83, 23, 99)
                      the program should display the list:
                      [0, 5, 4, 8, 16, 26, 36, 83, 64, 99]
                      You are not allowed to  use the concatenation of lists.
                   10.  Write a program that accepts a list of numbers from a user and replaces the elements at indices which are multiples of 3, by
                      the cube of the number at that index. Elements at other indexes should remain unchanged. For example, if the user enters
                      the list:



                                                                                                     Lists and Tuples  403
   412   413   414   415   416   417   418   419   420   421   422