【发布时间】:2013-03-18 03:47:14
【问题描述】:
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
【问题讨论】:
-
在您输入的另一个函数中,您是否也在使用“字典”变量?
-
是的,我应该只在每个函数中打开文件吗?
-
我想看看“另一个功能”的代码。
-
好的,我编辑了。
标签: python file-io python-3.x