Python Program to count the number of vowels in a string!

Here is another interesting Python program that will take a word or sentence as an input (basically a string) and return the number of vowels present in it.

There is numerous way you can write a Python program to count the number of vowels in a string, but here I am going to write as much as easily as possible.

#Python script to find vowels in a string
print "Enter a string:"

#define i
i = 0;

#get the input string
inpstr = raw_input()

#convert string to lower case
inplower = inpstr.lower()

vowels = ['a','e','i','o','u']

#loop through each character 
for c in inplower:
    #if vowel found then increment i
    if c in vowels:
        i = i + 1

#print output
print "Number of vowels: "+ str(i)
        

Read the inline comments in the above script to understand it.

Output:

Enter a string:
agurchand
Number of vowels: 3

Enjoy coding!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top