How to save data in Pygame

Viewed 24

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

Code:

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 tried to find tutorials but none of them were useful. Share the code here if you solve the issue

IMPORTANT:

  1. I use PyCharm
  2. Add the code along with your answer
2 Answers

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.

UPDATE: This question has been answered.

Related