所以我有问题,我想计算python中的数字。我想要它,以便如果我问一个问题,用户得到10分,但是如果单击运行,它将变量重新回到0,因为变量等于零。有没有办法永久存储点,以便当我再次运行时,这些点仍然存在。
我是菜鸟,所以我不知道该怎么做 我也刚开始学习python,所以我不了解很多,所以您能以简单的术语向我解释一下,因为我刚开始学习却一无所知
答案 0 :(得分:2)
我认为您应该看看如何在python中读取和写入文本文件
#get score in your program and then do this
score = 10
def saveScore(x):
file = open("myfile.txt","a")
file.write(str(x)+'\n')
file.close()
def readScore():
file = open("myfile.txt","r")
return file.readlines()[-1]
#save score everytime time it changes
saveScore(score)
#this function will score of last saved state
score = readScore()