Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

python count vowels in string

python program to get a String and count the number of vowels occurred in string.

Sample Input 1 :

Hello

Sample Output 1 :

2

Program or Solution

					    
							
s=input("Enter a String:")
vowels=0
for i in s:
      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(vowels)

					    
					

Program Explanation

visit each location in string s, if the character in the location is a vowel then increment vowels by 1.