codescracker


python

Python Program to Count Number of Each Vowels in String



« Previous Program Next Program »


Count Number of Each Vowels in String in Python

To count total number of each vowels present in a string or sentence in python, you have to ask from user to enter a string and start counting the number of each vowels and finally display the result on the output screen as shown in the program given below.

Python Programming Code to Count Number of Each Vowels in String

Following python program ask from user to enter a sentence or string to count occurrence of each vowels present in that string:

# Python Program - Count Number of Each Vowels

print("Enter 'x' for exit.");
string = input("Enter any string to count number of each vowel: ");
if string == 'x':
    exit();
else:
    vowels = 'aeiou';
    string = string.casefold();
    count = {}.fromkeys(vowels,0);
    print();
    for char in string:
        if char in count:
            count[char] += 1;
    print(count);

Here is the sample run of the above Python program illustrating how to count number of each vowels present in a string:

count number of each vowel python

Above is the initial output produced by the program, now you have to enter any string say i am codescracker to count all how much time each vowel is present inside the given string or entered string vowels present in it:

count each vowel python

Same program on python shell:

python count number of each vowels

« Previous Program Next Program »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test