Monday, June 6, 2016

Counting the vowels

There are many ways to count the vowels in python, here is one


# Program to count vowels in given sentence

count=0
vowels={'a':0,'e':0,'i':0,'o':0,'u':0}

print "Program to count vowels in given sentence"

sentence=raw_input('Enter sentence? ')

for i in sentence:
if i.lower() in vowels.keys():
count+=1
vowels[i.lower()]+=1

print "Vowel count:", count
print "Each vowel count"
for k,v in vowels.items():

print '\t',k,':',v



No comments:

Post a Comment