Page 528 - Computer Science V2.0 Class 11
P. 528
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
'''
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
514 Touchpad Computer Science (Ver. 2.0)-XI

