import random
count=0
candidateWords = ['HELLO', 'GOODBYE', 'NAME', 'DAY', 'NIGHT', 'HOUR', 'POTATO', 'BIG', 'SMALL', 'GOOD', 'BAD', 'YES', 'NO', 'HOUSE', 'QUESTION', 'BALLOON', 'CAT', 'DUCK', 'PIGEON', 'POSTER', 'TELEVISION', 'SPY', 'RIPPLE', 'SUBSTANTIAL', 'SNOW', 'MAGNET', 'TOWEL', 'WALKING', 'SPEAKER', 'UNCHARACTERISTICALLY']
def countVowels(candidateWords):
vowel=['A','E','I','O','U']
for index in range (len(candidateWords)):
if vowel in candidateWords[0]:
count=count+1
return count
print(count)
else:
return False
当我试图执行这个代码部分时,实际上什么都不显示,我需要得到“HELLO”字的值的计数
可以将
sum
函数与生成器表达式一起使用,该表达式遍历列表中每个单词的每个字母,并测试字母是否为元音:不显示任何内容的主要原因是定义函数后没有调用它。还有其他的错误
下面是打印单词列表中所有单词的元音计数的正确代码:
相关问题 更多 >
编程相关推荐