[Python] I was experimenting with file reading in python and it just stopped working after i...

Discussão em 'Python' iniciado por Stack, Janeiro 30, 2025.

  1. Stack

    Stack Membro Participativo

    Here's the code

    login = open("login.txt", "a+")
    passw = open("passw.txt", "a+")

    state = 0
    print("What do you want to do?")
    print("1. Log in")
    print("2. Register")
    dec = int(input())
    if dec == 1:
    print("Enter your login:")
    log = input()
    print("Enter your password:")
    pas = input()
    if log == login.read() and pas == passw.read():
    print("You are logged in")
    state = 1
    login.close()
    passw.close()
    else:
    print("Incorrect login or password")
    state = 0
    login.close()
    passw.close()

    elif dec == 2:
    print("Enter your login:")
    log = input()
    print("Enter your password:")
    pas = input()
    login.write(log)
    passw.write(pas)
    print("You are registered")
    state = 1
    login.close()
    passw.close()

    if state == 1:
    print("What do you want to do?")
    print("1. Read the file")
    print("2. Write to the file")
    print("3. Log out")
    dec = int(input())
    if dec == 1:
    file = open("supasceret.txt", "r")
    print(file.read())
    file.close()
    elif dec == 2:
    file = open("supasecret.txt", "a+")
    print("Enter the text:")
    text = input()
    file.write(text)
    file.close()
    elif dec == 3:
    state = 0
    print("You are logged out")


    when i tried to add another function between lines 41-42 its suddenly stopped working even reverting the code and running it now still doesn't work and now it constantly says "Incorrect login or password". I even cleared the files and registered fromt he beggining still the same result

    I was logging in and was expecting to receive the message "You are logged in"

    Continue reading...

Compartilhe esta Página