PYTHON ONLY Write a function called count_vowels() using what we learned this we
ID: 3852071 • Letter: P
Question
PYTHON ONLY
Write a function called count_vowels() using what we learned this week about list and recursive function. Here are the requirements:
1. solution uses recursive function. A recursive function has exit condition, and statements that calls itself.
2. function count_vowels takes a parameter of a String type: count_vowels(mystr)
3. function count_vowels returns a integer of how many vowels there are in the string parameter
4. a vowel is any letter in a, e, i, o, u, A, E, I, O, U
5. function count_vowels collects all the vowels in the string parameter, and prints out all the vowels at the end.
6. here's an example of calling the function and the output:
>>> count = count_vowels("banana")
aaa
>>> count
3
Explanation / Answer
string=raw_input("Enter string:")
#this is count_vowels function calling
count_vowels(string)
#this is count_vowels function definition
def count_vowels(string):
vowels=0;
print("The vowels in the given string are:")
for i in string:
if(i=='a' or i=='A' i=='e' or i=='E' i=='i' or i=='I' i=='o' or i=='O' i=='u' or i=='U'):
print(i)
vowels=vowels+1
print("Number of vowels are:")
print(vowels)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.