I'm currently working on a simple little application that keeps track of wins and losses for any sort of game. I'm storing the win/loss count in separate text files as single numbers. What I want the program to be able to do is look into the specified text file, and simply add 1 to the existing number. For example, if the entire text file is simply "0" and I input "win" into the application, it will perform 0+1 and change the text file permanently to the result. Here's what I've got so far:
ld = open("data/lossdata.txt", "r+")
wd = open("data/windata.txt", "r+")
hlp = open("data/help.txt", "r+")
losread = ld.read()
winread = wd.read()
helpread = hlp.read()
to_write = []
print("Welcome to Track Lad. For help, input \"help\"\nCurrent Win Count: "+winread+"\nCurrent Loss Count: "+losread)
inp = input("Input: ")
if inp == "w" or inp == "win":
for line in wd:
num = int(line) + 1
to_write.append(num)
wd.reload()
wd.seek(0)
for num in to_write:
wd.write(str(num)+'\n')
wd.close()
print("New Win Count: "+winread+"\nLoss Count: "+losread)
input("")
elif inp == "l" or inp == "loss":
ld.write("1")
print("New Loss Count: "+losread+"\nWin Count: "+winread)
input("")
elif inp == "help":
print(helpread)
input("")
else:
print("Invalid input, try again.")
input("")
Everything I've done so far is in the first if statement. I'm not getting any error when I run the code, even when I input "w", but the number in the text file doesn't change. Thanks in advance for any help, and I'll stay on the page to answer any questions that may help you figure out what's wrong.