Dremendo Tag Line

Input a string and count vowels using a function in Python

Function - Question 2

In this question, we will see how to input a string and count how many vowels are there in it in Python programming using a function. To know more about function click on the function lesson.

Q2) Write a program in Python to input a string and count how many vowels are there in it using a function.

Program

def countvowels(str):
    vc=0
    for ch in str:
        ch=ch.lower()
        if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u':
            vc=vc+1
    return vc


# main program
s=input('Enter a String: ')
print('Total Number of Vowels =',countvowels(s))

Output

Enter a String: I am learning Python
Total Number of Vowels = 6
video-poster