xxxxxxxxxx
whatever=input("Enter something\n")
vowels = ['a', 'e', 'i', 'o', 'u']
vowelp = ([i for i in whatever if i in vowels])
vowelcount = len([i for i in whatever if i in vowels])
print ("there are", vowelcount, "vowels (y is not counted)")
print ("the vowels are:", vowelp)
xxxxxxxxxx
def vowel_count(string):
vowels = ['a', 'e', 'i', 'o', 'u']
return len([i for i in string if i in vowels])
xxxxxxxxxx
string = "hello world"
vowels = "aeiou"
vowel_count = 0
for char in string:
if char.lower() in vowels:
vowel_count += 1
print(f"the vowel in '{string}' is '{vowel_count}'")
xxxxxxxxxx
def get_vowels(word:str):
"""
return the number of vowels that has a word
Args:
word (str): the word used to find the number of vowels
"""
vowels = ['a', 'e', 'i', 'o', 'u']
number_of_vowels = 0
for letter in word:
for vowel in vowels:
if letter == vowel:number_of_vowels+=1;break
return number_of_vowels
xxxxxxxxxx
# Program to count the number of each vowels
# string of vowels
vowels = 'aeiou'
ip_str = 'Hello, have you tried our tutorial section yet?'
# make it suitable for caseless comparisions
ip_str = ip_str.casefold()
# make a dictionary with each vowel a key and value 0
count = {}.fromkeys(vowels,0)
# count the vowels
for char in ip_str:
if char in count:
count[char] += 1
print(count)
xxxxxxxxxx
# Using dictionary and list comprehension
ip_str = 'Hello, have you tried our tutorial section yet?'
# make it suitable for caseless comparisions
ip_str = ip_str.casefold()
# count the vowels
count = {x:sum([1 for char in ip_str if char == x]) for x in 'aeiou'}
print(count)