Write a function that counts the vowels (aeiou) in a string the user inputs. Make sure it counts upper- and lowercase vowels. Then write a routine that calls the function and displays the following output.

$ ./count_vowels.py
Enter some words: Go East young man!
The string "Go East young man!" has 6 vowels in it.


$ cat count_vowels.py
#!/usr/bin/python
def countVowels(my_string):
count = 0
for s in my_string:
if s.lower() in 'aeiou':
count += 1
return count
stg = raw_input('Enter some words: ')
print 'The string \"' + stg + '\"' + ' has ',
print countVowels(stg),
print 'vowels in it.'
Following is an alternative function that performs the same task:
$ cat count_vowels2.py
#!/usr/bin/python
def countVowels(my_string):
my_string = my_string.lower()
return len(my_string) - len(my_string.translate(None,'aeiou'))
stg = raw_input('Enter some words: ')
print 'The string \"' + stg + '\"' + ' has ',
print countVowels(stg),
print 'vowels in it.'

Computer Science & Information Technology

You might also like to view...

_____ explains the purpose of every major piece of computer code and also identifies and describes key variables.

A. Agile documentation B. Technical documentation C. Systems documentation D. User documentation

Computer Science & Information Technology

Write a method to lighten the darkest areas of a picture.

What will be an ideal response?

Computer Science & Information Technology

To select an entire word in a document by using a touchscreen, ________ the word

A) click B) double-tap C) tap D) double-click

Computer Science & Information Technology

Analysts often refer to the three ____'s when describing characteristics of Big Data.

A. C B. G C. D D. V

Computer Science & Information Technology