主要目标: 函数从文本文件中读取最高分数。 要传递到函数的参数: 文本文档!Python /函数参数
def highscore():
try:
text_file = open ("topscore.txt", "r")
topscore = int(text_file.read())
print topscore
text_file.close()
return topscore
except:
print "Error - no file"
topscore = 0
return topscore
如何添加文本文件作为参数?
你想传递一个路径字符串,并有此功能打开文件,或者你想传递一个文件对象,并有该功能操作? – dcolish
我真的不明白如何能够编写现有的代码并让它工作,而不必自己回答问题。 –