Program 5

 5. Write a program to count a number of vowels in a string?

Steps:

1. User must enter a string and store it in a variable.

2. The count variable is initialized to zero.

3. The for loop is used to traverse through the characters in the string.

4. An if statement checks if the character is a vowel or not.

5. The count is incremented each time a vowel is encountered.

6. The total count of vowels in the string is printed

string=input("Enter string:")

vowels=0

for i in string:

       if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'):

             vowels=vowels+1

print("Numbers of vowels are:")

print(vowels)

OUTPUT

Enter string: bgsit is a good college

Numbers of vowels 

Comments