In: Computer Science
Using the python program language. Expand/EDIT the code below for all vowels (AEIOU). Please provide a code and a screen shot of the code working with an output. the code should be able to take any name as an input. The code should be able to pull out the vowels along with the count fo each vowel within that name for the output.
#countVowels.py
import sys
s1 = str(sys.argv[1])
(a,e,i,o,u) = (0,0,0,0,0)
print ("String length = ", len(s1))
for n in range(0, len(s1)):
if (s1[n] == 'a'):
a += 1
elif s1[n] == 'e':
e += 1
print ("a count = ", a)
print ("e count = ", e)
c = len(s1) - a - e
print ("Consonants count ", c)
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
#ask user for the input
s1 = input("Enter your name : ")
#set variables to zero for vowels
(a,e,i,o,u) = (0,0,0,0,0)
#print string length
print ("String length = ", len(s1))
#loop for each character in string
for n in range(0, len(s1)):
#increase count corresponding
if (s1[n] == 'a'):
a += 1
elif s1[n] == 'e':
e += 1
elif s1[n] == 'i':
i += 1
elif s1[n] == 'o':
o += 1
elif s1[n] == 'u':
u += 1
#print each count
print ("a count = ", a)
print ("e count = ", e)
print ("i count = ", i)
print ("o count = ", o)
print ("u count = ", u)
#print consonants
c = len(s1) - a - e-i-o-u
print ("Consonants count ", c)
OUTPUT