I have created a simple command line game in python.
The user begins by inputting their nickname which is stored as name
At the end of the game the user's score is stored in a file like so:
wins = str(wins)
losses = str(losses)
file = open('scores.py','a')
file.write(name + ": wins = " + wins + " losses = " + losses + "\n\n")
file.close
( I converted the 'wins' and 'losses' variables to strings as I couldn't seem to write integers to a file, I don't know if this is possible (i'm sure it is) but I just didn't know how to do it. )
I want the user playing the game to have a cumulative score, i.e. if they were to play 1 game and win 6 rounds, play another game and win 2 rounds, I don't want there to by 2 entries in the 'scores.py' file, I would like it to say:
*User*: wins = 8 losses = 0
The only way I could think of doing this is that after each game finishes, the user's name and score would be appended to the 'scores.py' file, but before that, the file is scanned line-by-line to check whether or not the user's nickname already has an entered score. IF the name inputted at the start of the game is the same name as the one being read on the particular line in the 'scores.py' file, extract the line, convert the string values for wins and for losses to integers, add the current score in the game to the stored score, and then write it back into the file.
Any and all help would be greatly appreciated, and excuse me if the code is terrible and the solution is simple, I am extremely new to python and am not very well-versed in code in general either.