-3

Ok so, I have this bit of code

points = 25
points += 5

After the python code runs out or the program ends the points do not save and revert to the start 25 points how can I make it so that the points update and save in the new value.

Jacko P
  • 1
  • 1
  • Where do you wish to save them? – Basil Aug 06 '20 at 05:00
  • It is not clear what you are trying to do. Is it the case that you want the value to be the same when you start the program again? If that is the case, then you need to store this value externally and read it every time in the program. – alt-f4 Aug 06 '20 at 05:00
  • You should not end the program if you wanna keep things running or else if you want you paste the value of the `variable` in a text file and then pick the value from there next time – Heisenberg Aug 06 '20 at 05:01
  • @alt-f4 yes sorry I want the value to be the same when I load it up how can i do this? im quite new to coding – Jacko P Aug 06 '20 at 05:04
  • I assume you want to store the state of the program and again resume from the same state. Is that right? If thats the case, you may use serialization. In python you may achieve this using `pickle`. https://docs.python.org/3/library/pickle.html. While retrieving you may deserialize and restore the state. – DineshKumar Aug 06 '20 at 05:34

1 Answers1

0

Use the static data type to save the value, even after execution is complete.

Read this, https://www.studytonight.com/python/python-static-keyword

alphaX64
  • 71
  • 1
  • 7