Page 99 - TP_V5.1_C8_fb
P. 99

e.  Consider the following list:
                       L = [3, 5, 7, 9, 12, 15]

                       Write the Python code to find the position of the even number in the given list.
                     ______________________________________________________________________________________

                     ______________________________________________________________________________________

                     ______________________________________________________________________________________

                 5.  Write the output for the following codes in Python:

                    a.  test_str = "Good Morning"
                     print("The original string is : " + test_str)
                     hlf_idx = len(test_str)

                     res = ' '
                     for idx in range(len(test_str)):
                       if idx >= hlf_idx:
                            res+= test_str[idx].upper()
                      else:

                              res+= test_str[idx].upper()
                     print("The resultant string : " + res)
                     ______________________________________________________________________________________

                    b. def countX(lst, X):
                          count = 0
                         for ele in lst:
                                if(ele==X):
                                 count = count + 1

                         return count
                     lst = [5.24, 89, 5, 14, 5]
                     X = 5
                     print(X, "has occurred", countX(lst, X), "  times")
                     ______________________________________________________________________________________

                    c.  def swapList(newList):
                        size = len(newList)

                        temp = newList[0]
                        newList[0] = newList[size - 1]
                        newList[size - 1] = temp
                       return newList
                     newList = [12, 45, 9, 32, 24]
                     print(swapList(newList))
                     ______________________________________________________________________________________




                                                                                   Functions, String and List in Python  97
   94   95   96   97   98   99   100   101   102   103   104