Exercise 21

Write a program in Python language, which allows you to count the number of vowels in a given string. Example for the string s = 'anticonstitutionally' the program must return the following message: The string anconstitutionally has 9 vowels.

Solution

# program that determines the number of vowels in a string
# define vowels in string
vowels= {'a','e','y','u','i','o'}
# define string
s = "anticonstitutionally"
# getting the len of string
n = len(s)
# initialize number of vowels
number_vowels = 0
# browse all character of string s
for i in range(0,n):
if(s[i] in vowels):
number_vowels = number_vowels + 1
print("The number of vowels in string 's' is : ", number_vowels)
my-courses.net
One thought on “Solution Exercise 21”

Leave a Reply