Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 140 - 2620_Birla Open Mind C-8
P. 140

    C.     Answer the following questions:

                          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.

                  D.  Brain Boost.                                                                   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")

                      138  Premium Edition-VIII

| 135 136 137 138 139 140 141 142 143 144 145 |