Count Vowels in String Python
What you want can be done quite simply like so:
>>> mystr = input("Please type a sentence: ")
Please type a sentence: abcdE
>>> print(*map(mystr.lower().count, "aeiou"))
1 1 0 0 0
>>>
In case you don't know them, here is a reference on map
and one on the *
.
def countvowels(string):
num_vowels=0
for char in string:
if char in "aeiouAEIOU":
num_vowels = num_vowels+1
return num_vowels
(remember the spacing s)
>>> sentence = input("Sentence: ")
Sentence: this is a sentence
>>> counts = {i:0 for i in 'aeiouAEIOU'}
>>> for char in sentence:
... if char in counts:
... counts[char] += 1
...
>>> for k,v in counts.items():
... print(k, v)
...
a 1
e 3
u 0
U 0
O 0
i 2
E 0
o 0
A 0
I 0
data = str(input("Please type a sentence: "))
vowels = "aeiou"
for v in vowels:
print(v, data.lower().count(v))