再会!
我可以在我正在阅读并尝试学习 Python 的书中的样本上寻求帮助吗?
对于下面显示的代码。我从来没有定义过“each_score”,那么为什么这个“each_score”被 Python 识别并且运行良好呢?
scores={}
result_f=open("py score.txt")
for line in result_f:
(name,score)=line.split()
scores[score]=name
result_f.close()
print("The top scores were:")
for each_score in scores.keys():
print('surfer '+scores[each_score]+' scored '+each_score)
顺便说一句,文本文件内容很简单,如下所示:
Johnny 8.65
Juan 9.12
Joseph 8.45
Stacey 7.81
Aideen 8.05
Zack 7.21
Aaron 8.31