问题:你有一个单词,需要计算该单词中元音的数量。
解决方法: 您可以通过遍历单词中的每个字符并检查它是否是元音来计算单词中的元音。
下面是一个解决这个问题的 Python 代码示例:
def count_vowels (word):
vowels = ['a', 'e', 'i', 'o', 'u']
count = 0
for character in word:
if character in vowels:
count += 1
return count
# Input word
word = "programming"
# Count the vowels
vowel_count = count_vowels(word)
# Output the result
print(f"The word '{word} contains {vowel_count} vowels.")
