dictionary = open('dictionary.txt','r')
def main():
print("part 4")
part4()
def part4():
naclcount = 0
for words in dictionary:
if 'nacl' in words:
naclcount = naclcount + 1
return naclcount
main()
基本上它带有正确的答案 25,除非我在第 4 部分之前放入另一个函数,它将打印为 0。
def part1():
vowels = 'aeiouy'
vowelcount = 0
for words in dictionary:
words = words.lower()
vowelcount = 0
if len(words) == 8:
if 's' not in words:
for letters in words:
if letters in vowels:
vowelcount += 1
if vowelcount == 1:
print(words)
return words