71.9k views
1 vote
Assume s is a string of lower case characters. Write a program that counts up the number of vowels and their position in the string s. Valid vowels are: a, e, i, o and u. FOr example, if s = 'azcbobobegghakl', your program should print:

a - 0 12

e - 8

o - 4 6

User Bvj
by
5.6k points

1 Answer

1 vote

#read string input

str1 = input("please enter a string in lower case:")

#create a list of vowels

vowel = ['a','e','i','o','u']

#iterate over the string to find the position of each vowel

for ch in vowel:

#print the vowel

print(ch,end=" ")

for j,y in enumerate(str1):

if ch==y:

#print the index of vowel

print (j,end=" ")

print ()

Step-by-step explanation:

Read a string input and assign it to "str1" variable. Create a "vowel" list

and initialize it with all vowels. iterate over the string, for each vowel

it will print all the index at which this vowel present in the string. Similarly

repeat this for the next vowel and print their index.

Output:

please enter a string in lower case: ahcvasvcsakhvcsavuieoit

a - 0 4 9 15

e - 19

i - 18 21

o - 20

u - 17

User Macker
by
6.2k points