Reputation: 15
I wanted to test my program in the middle of writing it, but it won't start for some reason
CODE:
def main():
menu()
def menu():
print("1.Login\n2.Register\n\n1.Help")
input = int(input("Enter the corresponding number to the action you would like executed: "))
if input==3:
help()
if input==2:
register()
if input==1:
login()
def help():
print("\nIf you enter the number ONE (1) You will be prompted to login to the system\nIf you enter the number TWO (2) you will be prompted to register, so you can login")
def register():
usernameR = input("Enter your username: ")
with open("usernamesR.txt","wt") as output:
output.write(usernameR)
print("Your username is: "+usernameR)
passwordR = str(input("\nEnter your password: "))
with open("passwordsR.txt","wt") as output:
output.write(passwordR)
print("Your password is: "+passwordR)
def login():
print("")
if __name__=="__main__":
main()
This is the error I got:
1.Login
Traceback (most recent call last):
2.Register
File "C:/Users/Joseph/PycharmProjects/LearningPython/Login_System.py", line 30, in main()
1.Help
File "C:/Users/Joseph/PycharmProjects/LearningPython/Login_System.py", line 2, in main
menu()
File "C:/Users/Joseph/PycharmProjects/LearningPython/Login_System.py", line 5, in menu input = int(input("Enter the corresponding number to the action you would like executed: "))
UnboundLocalError: local variable 'input' referenced before assignment
Upvotes: 1
Views: 59
Reputation: 10223
input()
ins in build function,
In code you give variable name as input
, give different variable name.
def menu():
print("1.Login\n2.Register\n\n1.Help")
input = int(input("Enter the corresponding number to the action you would like executed: "))
# ^^^^
Upvotes: 0
Reputation: 6190
Your variable name input
clashes with the built-in method input
. The compiler is getting confused, thinking that the input()
call is calling your locally-bound variable, and then complaining that you haven't defined it yet. Changing your variable name to user_input
should fix this.
Upvotes: 0