我试图使一个游戏,保存一个高分,即使程序已经停止运行,这样,当我再次运行它,高分仍将保存。你知道吗
我怎么能这么做? 这就是我所尝试的:
def savehighscore(x):
with open('highscore.txt','w') as file:
file.write(str(x))
def play():
#Game code would go here and output a variable "highscore"
highscore=10 #Example
oldhighscore=open('highscore.txt')
if highscore>int(oldhighscore):
oldhighscore.close()
with open('highscore.txt','w') as file:
file.write(highscore)
savehighscore(5)
play()
它输出一个TypeError,表示“oldhighscore”不能转换为整数。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐