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
		
while True:
	print("Enter 'x' for exit.")
	string = input("Enter any string: ")
	if string == 'x':
		break
	else:
		vowels = 'aeiou'
		string = string.casefold()
		count = {}.fromkeys(vowels,0)
		for char in string:
			if char in count:
				count[char] += 1
		print(count,"\n")

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

python count number of each vowels

« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test