我的问题是,我在此脚本中不断收到未定义的全局名称错误:
import time
def cls():
print(("\n")*100)
#Registers the Username and Password for the user.
def registerPro():
cls()
username=str(input("Enter your Username here: "))
password=str(input("Enter your Password here: "))
confirm=str(input("Please confirm your Password: "))
if password==confirm:
cls()
print("Thank you for registering at Apex Industries!")
time.sleep(3)
loggingIn()
else:
cls()
print("Your passwords do not match, please re-register.")
time.sleep(3)
registerPro()
return username, password
#Is called by getUsername. If the user entered the password correctly then the login is successful.
def getPass(password):
cls()
confirmPass=str(input("Enter your password: "))
if confirmPass==password:
cls()
print("You have logged in successfully.")
else:
cls()
print("Wrong Password. Try again")
getPass()
#Makes sure the username is in the database.
def getUsername(username):
cls()
confirmUser=str(input("Enter your username: "))
if confirmUser==username:
getPass(password)
else:
cls()
print("No username with that name in the database.")
time.sleep(3)
loggingIn()
#The login for the main program.
def loggingIn():
cls()
print("Hello and welcome to the Apex Industries login/register page.")
print(" Please choose to either Login or Register.")
print()
regLog=str(input("Type Login or Register for your choice: "))
if regLog=='Login':
getUsername(username)
elif regLog=='Register':
registerPro()
else:
cls()
print("That is not a valid option. Try again.")
time.sleep(3)
loggingIn()
loggingIn()
我的回溯给了我这个:
Traceback (most recent call last):
File "C:/Users/Evu/Desktop/Python/testforLogin", line 59, in <module>
loggingIn()
File "C:/Users/Evu/Desktop/Python/testforLogin", line 13, in loggingIn
registerPro()
File "C:/Users/Evu/Desktop/Python/testforLogin", line 29, in registerPro
loggingIn()
File "C:/Users/Evu/Desktop/Python/testforLogin", line 11, in loggingIn
getUsername(username)
NameError: global name 'username' is not defined
我究竟做错了什么?我想将用户名导入到我创建的 getUsername() 函数中。请记住,我是脚本新手,我只是想在自己的时间学习,这只是一个测试脚本。任何建议都会很棒。