I hope I may be able to get some help. The point of this program is that it is supposed to take a count of the vowels in a sentence given by the user. I cannot get it to increase the count and everything is staying at zero. I was hoping someone may be able to help show me where I may have messed up the code. It has to stay in a very similar format with the for loop iterating directly over the string. I've tried manipulating it so many different ways. If anyone is able to help I am posting a the code that I have. Thanks!
VOWELS = 'AEIOU' def count3(string, letter): count = 0 # for loop only loops over index, don't initialize or incriminate index for char in string: #letters = string[char] letter_low = str.lower(letter) if char == letter_low: count = count + 1 return (letter + " : %d" % count) # come back to this, not increasing count of each vowel def main(): print("Enter a sentence and this sentence will display its vowel count.") sent = input("Enter the sentence to be analyzed: ") while sent: print("Your sentence was: " + sent) sent_low = str.lower(sent) print("\nAnalysis") for letter in VOWELS: print(count3(sent_low, letter))
forloop inside yourmainfunction. Also, I think that thewhileloop is going to be infinite, meaning you won't even ever enter thefor letter in VOWELSloop, and thus won't ever call yourcount3function.