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

'''

                 vowels = "AEIOUaeiou"
                 result = ""
                 seenVowels = set()
                 for char in string:

                      if char in vowels and char not in seenVowels:
                         result += char * num
                         seenVowels.add(char)
                 return result

             string = input("Enter a string:")

             num = int(input("Enter N:"))
             output = repeatUniqueVowels(string, num)
             print(output)
        Program 38

        Write a program that accepts a string and displays the count of the number of words in the string.

        Ans. def countWords(string):
                 '''
                 Objective : To count number of words in a string
                 Input Parameter : string

                 Return Value : len(words) – numeric value
                 '''
                 words = string.split()
                 return len(words)
             string = input("Enter a string: ")

             wordCount = countWords(string)
             print(f"Number of words in the string: {wordCount}")
        Program 39

        Write a program that accepts a list of n numbers and displays the number that appears the maximum number of
        times.
        Ans. def findMostFrequent(numbers):
                 '''

                 Objective : To find the number that appears the maximum number of times
                 Input Parameter : numbers - list
                 Return Value : mostFrequentNumbers - list
                 '''
                 countDict = {}

                 for num in numbers:
                     if num in countDict:


         448   Touchpad Computer Science-XI
   445   446   447   448   449   450   451   452   453   454   455