Python program to count the number of vowels in a string
Count the number of vowels in a string
A string is a combination of the alphabet or we can say alphabets are building blo0cks of a string, but in programing String can be of a 1 length as ‘a’ is also treated as a string and ‘abcde’ is also treated as string. In English 26 alphabets are divided into two categories ‘Vowels’ and ‘Consonants’. Vowels are sound and are 5 from a total of 26 alphabets [A, E, I, O, U] other all 21 alphabets are grouped as consonants.
In this python program, we will be traversing through each and every alphabet of a string to find the number of vowels present in the string.
- Step 1:- Start.
- Step 2:- Take user input.
- Step 3:- Initialize count variable.
- Step 4:- Iterate through the string to find number of vowels.
- Step 5:- Check if the alphabet of the string lies under the group of vowels.
- Step 6:- If TRUE increment count by 1.
- Step 7:- Print count.
- Step 8:- End.
Python program to count number of vowels in a string
#take user input String = input('Enter the string :') count = 0 #to check for less conditions #keep string in lowercase String = String.lower() for i in String: if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u': #if True count+=1 #check if any vowel found if count == 0: print('No vowels found') else: print('Total vowels are :' + str(count))
Enter the string :PrepInsta
Total vowels are :3