Write a Python Program to Count the Number of Each Vowel

Python Program to Count the Number of Each Vowel

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Count the Number of Each Vowel
Python Program to Count the Number of Each Vowel

Write a Python Program to Count the Number of Each Vowel

PROGRAM: Python Program to Count the Number of Each Vowel

/* Python Program to Count the Number of Each Vowel */

# Program to count the number of each vowels

# string of vowels
vowels = ‘aeiou’

ip_str = ‘Hello, have you tried our tutorial section yet?’

# make it suitable for caseless comparisions
ip_str = ip_str.casefold()

# make a dictionary with each vowel a key and value 0
count = {}.fromkeys(vowels,0)

# count the vowels
for char in ip_str:
if char in count:
count[char] += 1

print(count)

Output:

{'a': 2, 'e': 5, 'i': 3, 'o': 5, 'u': 3}:
 

		

Leave a Reply

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