so I'm very basic with coding and Python. I used to be much better but haven't used it in some time and I'm trying to get back into the swing of things. I'm trying to execute an If statement, where input is asked for a username and password, if correct it then goes to a "definition" I think it's called, where it then executes the code in def access()
Code:
def main():
userName = ("u123")
userPass = ("p123")
userNameInput = input("Username: ")
userPassInput = input("Password: ")
if userPassInput == userPass and userNameInput == userName:
print("Access granted")
access()
else:
print("Access denied")
return main()
def access():
print("Welcome, " + userName)
access()
main()
However, I get this error when the correct inputs are executed:
Username: u123
Password: p123
Access granted
Traceback (most recent call last):
File "C:/Users/Tom/Desktop/test.py", line 23, in <module>
main()
File "C:/Users/Tom/Desktop/test.py", line 11, in main
access()
UnboundLocalError: local variable 'access' referenced before assignment
>>>
Any help will be appreciated, thank you.