我已经测试了下面显示的代码(使用变量),并且当我查看它(使用记事本)时,文本文件显示'answer:NONE'
。请您仔细阅读这段代码,指出我的错误,非常感谢
这是在Python中,并使用变量对其进行测试
例如:points = 10
,name = 'Alex'
#Creating text file to save scores
f = open('scores.txt','w')
a = print(name, points)
f.write('answer:'+str(a))
f.close()
#ordering scores in descending order
scores = []
with open("scores.txt") as f:
for line in f:
name, score = line.split(',')
score = int(points)
scores.append((name, score))
scores.sort(key=lambda s: s[1])
for name, score in scores:
print(name, score)
sys.exit("Best luck nest time, your scores have been recorded")