s = input("Enter a sentence: ")
emp = ""
vow = 0
for i in s: if i.isspace() == False:emp = emp+ielse:for j in emp:if j in 'aeiouAEIOU':vow = vow+1print("The number of vowels in", emp, "are", vow)emp = ""
It only gives vowels for the first word.
s = input("Enter a sentence: ")
emp = ""
vow = 0
for i in s: if i.isspace() == False:emp = emp+ielse:for j in emp:if j in 'aeiouAEIOU':vow = vow+1print("The number of vowels in", emp, "are", vow)emp = ""
It only gives vowels for the first word.
Your code is not working because the variable vow
is never reset to 0. You should reset it for each new word you encounter, else it will print the total of vowels in your string.
A better solution is to make use of split()
instead of isspace()
, so words are "automatically" separated.
Then, you can iterate trough each word, and sum up letters which are vowels.
words = s.split()
for word in words:vow = sum(letter in 'aeiou' for letter in word.lower())print("The number of vowels in", word, "are", vow)