- def num_vowels(s):
- '''Return the number of vowels in string s.
- The letter "y" is not treated as a vowel.'''
- count = 0
- for char in s:
- if char in "aAeEiIoOuU":
- count = count + 1
- return count
- def askAndCountRepeat():
- ''' Prompt the user to enter a string and find out if it
- contains any vowels. Repeat this task until a string
- containing a vowel is found. When you find a string
- containing a vowel, return the number of vowels in
- that string (an int)'''
- num = 0
- while num == 0:
- myString = input("Enter a string: ")
- num = num_vowels(myString)
- return num
- def main():
- num = askAndCountRepeat()
- print("Finally! Found a string with vowels.")
- print("It has",num,"vowels")
- main()
Raw Paste