CBSE Class 11 Computer Science
Question 17 of 19
Strings in Python — Question 17
Back to all questions 17
Question Write a program to count the number of each vowel in a given string.
input_string = input("Enter a string: ")
vowel_count = {'a': 0, 'e': 0, 'i': 0, 'o': 0, 'u': 0}
input_string = input_string.lower()
for char in input_string:
if char in vowel_count:
vowel_count[char] += 1
print("Vowel counts:", vowel_count)Enter a string: The quick brown fox jumps over the lazy dog.
Vowel counts: {'a': 1, 'e': 3, 'i': 1, 'o': 4, 'u': 2}
input_string
=
input
(
"Enter a string: "
)
vowel_count
=
{
'a'
:
0
,
'e'
:
0
,
'i'
:
0
,
'o'
:
0
,
'u'
:
0
}
input_string
=
input_string
.
lower
()
for
char
in
input_string
:
if
char
in
vowel_count
:
vowel_count
[
char
]
+=
1
print
(
"Vowel counts:"
,
vowel_count
)
Output
Enter a string: The quick brown fox jumps over the lazy dog.
Vowel counts: {'a': 1, 'e': 3, 'i': 1, 'o': 4, 'u': 2}