Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
there seem to bee a problem in this python code
which i don't know were is it
simple vowel counter code
Python
vowels = ['a','i','e','o','u']
while(True):
    print("\n\n\n\n\n\n")
    numOfVowels = 0
    Word = input("Please Enter a word to count vowles in it:")
    for letter in Word:
        if (letter in vowels):
            numOfVowels+=1;
    print("There is a " + str(numOfVowels) + " vowel letter in the word")
    choice = input("would you like a vowels summary:  (y/n)  : ")
    if(choice == 'y'):

        for i in Word:
            if (i in vowels):
                num = Word.find(i) #each letter counter
                if(num > 0):
                     print("number of " + i + " is " + str(num) ) 
#        print("number of a is " + str(Wo) )

    elif(choice == 'n'):
        print("OK \n ")


What I have tried:

vowels = ['a','i','e','o','u']
while(True):
print("\n\n\n\n\n\n")
numOfVowels = 0
Word = input("Please Enter a word to count vowles in it:")
for letter in Word:
if (letter in vowels):
numOfVowels+=1;
print("There is a " + str(numOfVowels) + " vowel letter in the word")
choice = input("would you like a vowels summary: (y/n) : ")
if(choice == 'y'):

for i in Word:
if (i in vowels):
num = Word.find(i) #each letter counter
if(num > 0):
print("number of " + i + " is " + str(num) )
# print("number of a is " + str(Wo) )

elif(choice == 'n'):
print("OK \n ")
Posted
Updated 7-Aug-17 23:18pm
Comments
Patrice T 8-Aug-17 1:22am    
Describe the problem !

1 solution

It seems that you interchange counts and vowels in the messages and the code:
Python
#print("There is a " + str(numOfVowels) + " vowel letter in the word")
print("There are " + str(numOfVowels) + " vowels in the word")

# This makes no sense
#for i in Word:
#    if (i in vowels):
#        num = Word.find(i) #each letter counter
#        if(num > 0):
#             print("number of " + i + " is " + str(num) ) 

# You probably want to show the count of each vowel
# So you have to loop through the vowels and count the occurences
for i in vowels:
    num = 0
    for letter in Word:
        if (letter == i)
            num += 1
    print("The vowel '" + i + "' occurs " + str(num) + " times") 
 
Share this answer
 
Comments
Member 12173667 8-Aug-17 12:07pm    
thanks ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900