我目前正在编写一段代码,用户根据他们在游戏中的表现得分来设置分数,我被卡住了。任何人都可以提供一些关于如何在用户计算机上创建本地文件的建议,并检索它以配置新的高分(如果有的话),然后打印最高的三个并删除其他三个以节省空间。如何创建本地高分? - Python
这是我此刻的代码,但它是在改善严重的需要:
print("Yore score is", score, "/30")
if sthighscore < score:
sthighscore = score
sthighscorename = name
print("NEW 1st HIGH SCORE: ")
print('1: ',sthighscorename, '-', sthighscore)
print("2: ", ndhighscorename, '-', ndhighscore)
print('3: ', rdhighscorename, '-', rdhighscore)
elif sthighscore >= score > ndhighscore:
ndhighscore = score
ndhighscorename = name
print("NEW 2nd HIGH SCORE: ")
print('1: ', sthighscorename, '-', sthighscore)
print("2: ", ndhighscorename, '-', ndhighscore)
print('3: ', rdhighscorename, '-', rdhighscore)
elif ndhighscore >= score > rdhighscore:
rdhighscore = score
rdhighscorename = name
print("NEW 3rd HIGH SCORE: ")
print('1: ',sthighscorename, '-', sthighscore)
print("2: ", ndhighscorename, '-', ndhighscore)
print('3: ', rdhighscorename, '-', rdhighscore)
else:
print("NO NEW HIGH SCORES :(")
print('1: ',sthighscorename, '-', sthighscore)
print("2: ", ndhighscorename, '-', ndhighscore)
print('3: ', rdhighscorename, '-', rdhighscore)
正如你所看到的代码量还没有存储任何。请帮忙。
您是否尝试过做的文件在Python处理一些研究? – jonrsharpe
我对这个问题仍然陌生,因为你可能能够说出并尝试过研究,但在我的问题上找不到任何东西,所以我在这里问了一下,希望人们能够教我一些东西。 –
这不是教程网站,您的问题在这里不合适。有许多关于文件处理的在线教程,包括[官方教程](https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files)。还有一些书籍:[Python Crash Course](https://www.nostarch.com/pythoncrashcourse/)有一节(第14章),用于节省游戏的高分。 –