Page 449 - Computer Science Class 11 With Functions
P. 449

else:

                         return "Substring DOES NOT exist."

                 string1 = input("Enter the first string: ")
                 string2 = input("Enter the second string: ")

                 result = findSubstring(string1, string2)
                 print(result)
            Program 36

            Write a function that takes a string, s and a number n as input arguments. The function displays all vowels in the
            string n number of times, in the string in the same sequence in which they appear in the input string. For example,
            if the value of s is helicopter and the value of n is 5, the output should be:

                 eeeeeiiiiieeeee
            Ans. def repeatVowels(string, num):
                      '''

                      Objective : To repeat vowels in a string n number of times
                      Input Parameter : string and number-numeric value
                      Return Value : result - string
                      '''
                      vowels = "AEIOUaeiou"
                      result = ""

                      for char in string:
                          if char in vowels:
                              result += char * num
                      return result



                 string = input("Enter a string:")
                 num = int(input("Enter N:"))
                 output = repeatVowels(string, num)
                 print(output)
            Program 37

            Write a function that takes a string, s and a number n as arguments. The function should display all vowels in
            the string n times in the string in the same sequence in which they appear in the input string. If a vowel appears
            multiple times, it should still be displayed n times, but not repeatedly for multiple occurrences of the same vowel.
            For example, if the value of s is helicopter and the value of n is 5, the output should be:

            eeeeeiiiii
            Ans. def repeatUniqueVowels(string, num):

                     '''
                     Objective : to repeat vowels in a string n number of times
                     Input Parameter : string and num-numeric value
                     Return Value : result - string



                                                                                                      Practical  447
   444   445   446   447   448   449   450   451   452   453   454