因此,我能够创建一个程序来计算计算机上的文本文件中元音(特别是 eio)的数量。但是,我一生都无法弄清楚如何显示哪一个出现最多。我以为我会说类似的话
for ch in 'i':
return numvowel?
我只是不太确定步骤是什么。我基本上希望它最后输出“字母 i,在文本文件中出现次数最多”
def vowelCounter():
inFile = open('file.txt', 'r')
contents = inFile.read()
# variable to store total number of vowels
numVowel = 0
# This counts the total number of occurrences of vowels o e i.
for ch in contents:
if ch in 'i':
numVowel = numVowel + 1
if ch in 'e':
numVowel = numVowel + 1
if ch in 'o':
numVowel = numVowel + 1
print('file.txt has', numVowel, 'vowel occurences total')
inFile.close()
vowelCounter()