Page 126 - TP_Play_V2.2_Class8
P. 126

Q    Answer the following questions:
                  A
                      1.  What is the use of functions?




                      2.  What do you mean by traversing a string? Give an example.



                      3.   How can we call a function in Python? Explain using an example.






                      4.   What are the different types of functions? Explain in detail.





                      5.   Write any two built-in functions to manipulate strings.






                     Scratch Your Brain.                                                         Century   #Critical Thinking
                                                                                                   21 st
                                                                                                  Skills
                                 1.  Write the output of the following programs:
                         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 : " + test_str)

                          b.  def countX(st, X):

                                count = 0
                                for ele in st:
                                    if(ele==X):
                                        count = count + 1
                                return count
                            st = "Orange Education"
                            X = 'a'
                            print(X,"has occurred", countX(st, X), "times")










                  124  Plus (Ver. 4.0)-VIII
   121   122   123   124   125   126   127   128   129   130   131