import pickle
try:
    with open('score.dat', 'rb') as file:
        score = pickle.load(file)
except:
    score = 0
print('High score: %d' % score)
score = 10
with open('score.dat', 'wb') as file:
    pickle.dump(score, file)
Saving the highscore for a python game