1

I am trying to learn python and I created some lines of codes, and in theses lines, I created a system of login. So I created a system of logout too. BUT, when I tried to put the name's variable into another to register it, an error was displayed as : UnboundLocalError: local variable 'name' referenced before assignment So I checked this website and it tell me to put the variable in global, and when I tried, another error was displayed as : SyntaxError: name 'name' is used prior to global declaration Can somebody here help me?

def menu():
    menu=input("type 1 to logout and login after : ")
    if menu="1":
    print("")
    print("You're now logout.")
    print("")
    menu=int(menu)
    log_name=name
    log_password=password


    name_inscription_confirm=0
    password_inscription_confirm=0
    print("")
    print("Hello,")
    print("")
    name_inscription=input("What's your name?")

    while name_inscription_confirm==0:
        print("")
        name_inscription=input("What's your name?")

        if name_inscription==log_name:
    
            name_inscription_confirm=1

            password_inscription=input("What's your password?")

            if password_inscription==log_password:
                print("Welcome back '{}'!".format(log_name))

                password_inscription_confirm=1
            else:
                print("")
                print("incorrect password") 
                password_inscription_confirm=0


        else:
            print("incorrect username")
            name_inscription_confirm=0
            continue

        pass

    pass

And then:

name=input("Choose your name : ")
print("")
password=input("Choose your password : ")
Stardaz
  • 11
  • 2
  • 2
    Does this answer your question? [Local variable referenced before assignment?](https://stackoverflow.com/questions/18002794/local-variable-referenced-before-assignment) – 0x5453 Jul 11 '22 at 18:24
  • Can you post the change made to your code? – Scott Hunter Jul 11 '22 at 18:38

1 Answers1

0

In log_name=name, it doesn't know that you mean the global name (which you did assign to), and assumes it is a local one (which hasn't been assigned to).

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101