myString=input("Please enter your line of text: ")
vowels='aeiouAEIOU'
#we initialize a flag variable that will find the vowels with false
vowelfound=0
i=1
#we initialize the accumulator counters for vowels with 0
countA=countE=countI=countO=countU=0
for char in myString:
if myString[i-1]=='a' or myString[i-1]=='A':
vowelfound=1
countA=countA+1
elif myString[i-1]=='e' or myString[i-1]=='E':
vowelfound=1
countE=countE+1
elif myString[i-1]=='i' or myString[i-1]=='I':
vowelfound=1
countI=countI+1
elif myString[i-1]=='o' or myString[i-1]=='O':
vowelfound=1
countO=countO+1
elif myString[i-1]=='u' or myString[i-1]=='U':
vowelfound=1
countU=countU+1
if vowelfound==0:
print('There are no vowels in your line of text.')
else:
if countA>countE:
print('The most occuring vowel is A or a,with: ',countA,' occurrences')
elif countE>countI:
print('The most occuring vowel is E or e,with: ',countE,' occurrences')
elif countI>countO:
print('The most occuring vowel is I or i,with: ',countI,' occurrences')
elif countI>countU:
print('The most occuring vowel is E or e,with: ',countE,' occurrences')
else:
print('The most occuring vowel is U or u,with: ',countU,' occurrences')
But for example if my line of text is :Are you Bart,instead of displayind the ouput that the vowel 'a'has 2 occurences it gives the number 6,so 3 times more than the actual number of occurences.What I'm doig wrong?Thanks in advance.

New Topic/Question
Reply



MultiQuote





|