Programming Examples

Python program to find the frequency of vowels in each word


Write a Python code to accept a sentence in lowercase. Find the frequency of vowels in each word and display the words along with frequency of vowels.

Sample Input: understanding computer science

Sample Output: Word No. of vowels

Understanding 4

Computer 3

Science         3

Solution:
wd="";nwd="";b=v=0
str=input("Enter a string in lowercase: ")
str=str+" "
p=len(str)
print("Word\t\t\t No. of vowels")
for i in range(0,p):
    if(str[i]==' '):
        b=len(wd)
        v=0
        for j in range(0,b):
            if(wd[j]=='a' or wd[j]=='e' or wd[j]=='i' or wd[j]=='o'or wd[j]=='u'):
                v=v+1
        print(wd,"\t\t\t",v)
        wd=""
    else:
        wd=wd+str[i]
Output/ Explanation:

Enter a string in lowercase: python is very easy language

Word No. of vowels

python 1

is          1

very 1

easy 2

language  4

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad