Page 125 - Trackpad_V2.1_class8
P. 125

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))
                      _______________________________________________________________________________

                    d.  l1 = ['O', 'r', 'a', 'n', 'g', 'e']
                     l1.extend(['E', 'd', 'u', 'c', 'a', 't', 'i', 'o', 'n'])
                     print(l1)

                     print(l1[-3])
                      _______________________________________________________________________________

                      _______________________________________________________________________________



                           SDG Activity



                    Design a simple computer network to track and monitor waste production and
                    recycling  in your school. Create  a program that  collects  data  from different
                    classrooms, displays yearly wastage, and suggests ways to reduce it.












                                                                                   Functions, String and List in Python  123
   120   121   122   123   124   125   126   127   128   129   130