In this program, we will take a string as input and count the number of vowels in a string.
Steps to solve the program
- Take a string as input.
- Create a list containing all the vowels and a count variable and assign its value equal to zero.
- Use For loop to iterate over each character of the string.
- If the character is a vowel add 1 to the count variable.
- Print the output.
#Input string
string = "I am learning python"
vowel = "aeiou"
count=0
for char in string:
if char.lower() in vowel:
count += 1
#Printing output
print("Number of vowels: ",count)
Output :
Number of vowels: 6