Input sentence and print each word with number of vowels present in it in Python
String Methods - Question 9
In this question, we will see how to input a sentence and print each word along with the number of vowels present in it in Python programming. To know more about string methods click on the string methods lesson.
Q9) Write a program in Python to input a sentence and print each word along with the number of vowels present in it.
Program
w=""
vowels='aeiou'
vc=0
str=input("Enter a sentence\n")
str=str+" "
for i in range(0,len(str)):
if str[i]!=' ':
w=w+str[i]
else:
for ch in w:
ch=ch.lower()
if vowels.find(ch)>=0:
vc=vc+1
print(w,'=',vc)
w=""
vc=0
Output
Enter a sentence My hobby is to read novels and watch movies My = 0 hobby = 1 is = 1 to = 1 read = 2 novels = 2 and = 1 watch = 1 movies = 3