Skip to content

Commit 9dad1bd

Browse files
committed
Count number of each vowels in string
1 parent acb55d3 commit 9dad1bd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

count_vowels.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
__author__ = 'Avinash'
2+
3+
4+
# Python3 program to count vowels in a string
5+
6+
# string of vowels
7+
vowels = 'aeiou'
8+
9+
input_str = input("Enter a string: ")
10+
11+
# make input string case insensitive
12+
input_str = input_str.casefold()
13+
14+
# make a dictionary with each vowel a key and value 0
15+
vowels_count = {}.fromkeys(vowels, 0)
16+
17+
# count the number of each vowels
18+
for letter in input_str:
19+
if letter in vowels_count:
20+
vowels_count[letter] += 1
21+
22+
print(vowels_count)

0 commit comments

Comments
 (0)