+ 1

Help me with this python problem ??

AssumeĀ sĀ is a string of lower case characters. Write a program that counts up the number of vowels contained in the stringĀ s. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'. For example, ifĀ s = 'azcbobobegghakl', your program should print: Number of vowels: 5

29th Mar 2018, 1:03 AM
RAVI WANTED
RAVI WANTED - avatar
3 Answers
+ 4
I don't want to give you the answer directly, so I'll just suggest some things that you can do. What I would do when making a program like this would be to create a loop that goes through the string, held in a variable, with an if statement within the loop to check if the value that loop is currently at is equal to a vowel.
29th Mar 2018, 1:38 AM
Faisal
Faisal - avatar
+ 3
Using list comprehension you can do this in one line like so: len([l for l in s if l in 'aeiouAEIOU']) where s is the string you wish to check. This would be the same as creating an empty list and then looping over the string checking each letter if it is a vowel and then adding the letter to the list. When done you check the length of the list to get the number of vowels in that string. The long form would look like: c=[] for l in s: if l in 'aeiouAEIOU': c.append(l) len(c)
29th Mar 2018, 3:41 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
use any loop check if s[index] is equal to vowels if yes add 1 to some variable
29th Mar 2018, 3:29 AM
ā€ŽĀ ā€ā€ā€ŽAnonymous Guy