[英]Error with referenced before assignment in python
I am trying to create a login and register program in simple console python, however when trying to make a loop that will check if the username contains a digit I keep getting the error, ("UnboundLocalError: local variable 'includesDigit' referenced before assignment") the code is:我正在尝试在简单的控制台 python 中创建一个登录和注册程序,但是当尝试创建一个循环来检查用户名是否包含数字时,我不断收到错误消息,(“UnboundLocalError:分配前引用的局部变量‘includesDigit’” ) 代码是:
def register():
incluesDigit = False
print("")
print("Create Account")
print("~~~~~~~~~~~~~~")
print("Username: ")
registerUsername = input("")
for char in registerUsername:
if char.isdigit():
includesDigit = True
if includesDigit == True:
print("Please enter a username that does not contain a number")
register()
print("Password: ")
registerPassword = input("")
if len(registerPassword) < 5:
print("Please enter a password that is atleast 5 characters")
register()
if len(registerPassword) > 15:
print("Please enter a password that is less than or fifteen character")
logCreate = open("C:\\Desktop\\Login Program\\Accounts\\" + registerUsername + ".txt", "w")
logCreate.write(registerPassword)
logCreate.close()
login()
There is a typo in line 2.第 2 行有一个错字。
incluesDigit = False
Should be应该
includesDigit = False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.