我目前正在編寫一段代碼,用戶根據他們在遊戲中的表現得分來設置分數,我被卡住了。任何人都可以提供一些關於如何在用戶計算機上創建本地文件的建議,並檢索它以配置新的高分(如果有的話),然後打印最高的三個並刪除其他三個以節省空間。如何創建本地高分? - 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章),用於節省遊戲的高分。 –