Dec-16-2019, 11:39 AM
def checkUserDesiredMethod(): userDesiredMethod=input("Would you like to register an account or login?\n(reg) /\n(login) /\n(none) /\n").lower() if userDesiredMethod=="reg": userWantsToRegister=True elif userDesiredMethod=="login": userWantsToLogin=True elif userDesiredMethod=="none": pass else: errorType("invalidInput") def performUserDesiredMethod(): if userWantsToRegister: regAcc() elif userWantsToLogin: loginMethod() else: print("Error")So here is part of my password system in python. Don't worry, I have defined regAcc(), loginMethod() and errorType() and as far as I am aware, they are not what is causing the issue. But later on in the script I write this:
checkUserDesiredMethod() performUserDesiredMethod()and when I run the script, after I enter something for the input, there is an error and it says
Error:Traceback (most recent call last):
File "C:\Users\Student\Python\passwordSystem.py", line 108, in <module>
performUserDesiredMethod()
File "C:\Users\Student\Python\passwordSystem.py", line 96, in performUserDesiredMethod
if userWantsToRegister==True:
NameError: name 'userWantsToRegister' is not defined
I'm not sure why it says that userWantsToRegister is not defined as it is defined in the subroutine checkUserDesiredMethod() as a boolean data type / boolean variable (if necessary), for example if I enter 'reg' for the input for the ' userDesiredMethod=input("Would you like to register an account or login?\n(reg) /\n(login) /\n(none) /\n").lower() ' part of the checkUserDesiredMethod function, then userWantsToRegister is assigned 'True' but if I input anything other than 'reg' then userWantsToRegister is not defined or assigned anything, but apparently, even if I enter 'reg', userWantsToRegister is not defined anyway, even though I have entered 'reg' which is supposed to fulfill the requirement for the the 'if' statement in the checkUserDesiredMethod() function which leads to userWantsToRegister being assigned 'True':(if userDesiredMethod=="reg":
userWantsToRegister=True).
Do you know what is causing the error and how I can make the program proceed to performing the subroutine regAcc() if userWantsToRegister==True, or loginMethod() if userWantsToLogin==True? (and so basically just doing what performUserDesiredMethod() is supposed to do?)