Variable not defined in password checker - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Variable not defined in password checker (/thread-4569.html) |
Variable not defined in password checker - DAS - Aug-27-2017 I have used the coding below to create a password strength checker but keep getting the upperCase variable not being recognised when I run the program. Any ideas? [Traceback (most recent call last): line 33, in <module> passwordStrength = upperCase + lowerCase + digitCase NameError: name 'upperCase' is not defined >>> Coding #Test for length of password entered, check length and if outside boundaries #say password has failed and why incorrectPass = False while not incorrectPass: password = (input("Please enter a password between 6 and 12 characters")) length = len(password) if len (password) <6 or len(password)>12: print ("Password needs to be between 6 and 12 characters, Password entered is only", length, "characters long") else: #setflag for strength test lowerCase = 0 upperCase= 0 digitCase= 0 for ch in password: if ch.islower(): lowerCase = 1 if ch.isupper(): upperCase= 1 if ch.isdigit(): digitCase= 1 #Strength ouput passwordStrength = upperCase + lowerCase + digitCase if passwordStrength ==1: print ("This is a weak password") elif passwordStrength ==2: print ("This is a medium password") if passwordStrength ==3: print ("This is a strong password") incorrectPass = True RE: Variable not defined in password checker - hbknjr - Aug-27-2017 Please use proper indentation and formatting. I had to indent your code and it works just fine. incorrectPass = False while not incorrectPass: password = (input("Please enter a password between 6 and 12 characters")) length = len(password) if len (password) <6 or len(password)>12: print ("Password needs to be between 6 and 12 characters, Password entered is only", length, "characters long") else: #setflag for strength test lowerCase = 0 upperCase= 0 digitCase= 0 for ch in password: if ch.islower(): lowerCase = 1 if ch.isupper(): upperCase= 1 if ch.isdigit(): digitCase= 1 #Strength ouput passwordStrength = upperCase + lowerCase + digitCase if passwordStrength ==1: print ("This is a weak password") elif passwordStrength ==2: print ("This is a medium password") if passwordStrength ==3: print ("This is a strong password") incorrectPass = True RE: Variable not defined in password checker - DAS - Aug-27-2017 Thank you for such a prompt reply The code works as long as you put the password between 6 and 12 words but when you put a password of say 3 characters the while loop does not work as it goes straight to the error message. RE: Variable not defined in password checker - nilamo - Aug-27-2017 (Aug-27-2017, 04:29 PM)DAS Wrote: a password of say 3 characters the while loop does not work as it goes straight to the error message.If the error message is anything other than print ("Password needs to be between 6 and 12 characters, Password entered is only", length, "characters long") , you would need to share it.
RE: Variable not defined in password checker - ichabod801 - Aug-27-2017 And check that the indentation that hbknjr used matches the indentation you are using. If the indentation is off, it could be causing that error. |