简体   繁体   中英

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:

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.

incluesDigit = False

Should be

includesDigit = False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM