Here , we are going to write python program to count the number of vowels in a string. To count number of vowels in string, we can use a for loop to traverse through the characters in the string and if statement to check if the character is a vowel or not
# python program to count number of vowels in string
# rading input from user
s=input("Enter any string:")
# intialising vaiable vowels
vowels=0
# Use a for loop to traverse through the characters in the string.
for i in s:
# Use an if statement to check if the character is a vowel or not
# and increment the count variable if it is a vowel.
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("Number of vowels are:")
print(vowels)
Output:
Enter any string:sumedh naik
Number of vowels are:
4
Enter any string: Athang dixit
Number of vowels are:
4
Python programs:
<