擅长:python、mysql、java
<p>作用域错误,还需要向函数访问中添加一个参数:</p>
<pre><code>def main():
userName = ("u123")
userPass = ("p123")
userNameInput = input("Username: ")
userPassInput = input("Password: ")
if userPassInput == userPass and userNameInput == userName:
print("Access granted")
#now you are able to use the function "access"
access(userName)
else:
print("Access denied")
return main()
#here, define the function in the same identation of the main function, not inside it
def access(userName):
print("Welcome, " + userName)
main()
</code></pre>