python

How to save data in Pygame


What I want to do is to save a variable for when I run the code again

a = 1
b = input("c or d")
if b == "c":
    a += 1
    print(f"you have {a} points")
if b == "d":
    a -= 1
    print(f"you have {a} points")

Still confused? The first time I run this, if I respond with "c", then the output should be "you have 2 points", the next time I run this and respond with "c", the output should be "you have 3 points". I am using PyCharm.


Solution

  • Use a database like SQLite3 or if you're on replit, you can use replit's db:

    from replit import db
    
    db['save'] = data
    

    replit's db work just like a dictionary except it saves.