I have a code that writes usernames, passwords and scores into a csv file in the format: username, password, score. I have it so it writes the username and password at the beginning of the code:
def login_system():
loggedin = False
while not loggedin:
login=input("Do you have an account? (yes/no) ")
loggedin=False
if login.lower()=="yes":
login=open("login.csv")
reader = csv.reader(login)
username=input("What is your username: ")
password=input("What is your password: ")
for row in reader:
if row[0]==username and row[1]==password:
print("Welcome " + username)
loggedin=True
login=open("login.csv","a")
login.write(username + "," + password + "\n")
login.close()
break
if loggedin==False:
print("Invalid username or password. Please try again.")
continue
I do this for user one and user 2.
print("User 1:")
login_system()
print("")
print("User 2:")
login_system()
In the code, this puts the usernames and passwords into column 0 and 1.
Then at the end after the game, it writes the score into the csv file. The part i'm struggling with is then writing the score into column 2. I need it to write on the next available cell in the csv file in row 2.
Any help on this would be greatly appreciated.
Dylan