#Password Checker Program
def lengthCheck(pWord):
if len(pWord) >= 6 and len(pWord) <= 12:
return True
else:
return False
def checkUpper(pWord):
for letters in pWord: #Why is my iteration not working?
upperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if upperLetters in pWord:
return True
else:
return False
def checkLower(pWord):
for letters in pWord: #Why is my iteration not working?
upperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lowerLetters = upperLetters.lower()
if lowerLetters in pWord:
return True
else:
return False
def checkDigit(pWord):
for letters in pWord: #Why is my iteration not working?
digitNumbers = "0123456789"
if digitNumbers in pWord:
return True
else:
return False
def complexCheck(pWord):
if checkUpper(pWord) and checkLower(pWord) and checkDigit(pWord):
return True
else:
return False
def passCheck(pWord):
if lengthCheck(pWord) and complexCheck(pWord):
return True
else:
return False
goodPWord = True
pWord = ""
pWord = input("Please enter your password: ")
goodPWord = passCheck(pWord)
if goodPWord:
print(pWord, " is a good password.")
else:
print(pWord, " is not a good password")
I need help with this problem, I can't the errors myself so plz help me. This my homework assignment from school I need help with this problem, I can't the errors myself so plz help me. This my homework assignment from schoolI need help with this problem, I can't the errors myself so plz help me. This my homework assignment from school enter image description here
I'll focus on checkUpper and then you can replicate in the other two functions.
You have two main problems.
The first problem is that you're trying to match the entire string of upperLetters to see if it exists in pWord, even though you're looping pWord. Instead, you need to check if the currently looped letter is inside upperLetters.
This:
if upperLetters in pWord:
Should be this instead:
if letters in upperLetters:
You're looping pWord and getting a letter at a time (which you called
letters
). That's what you need to compare to upperLetters, not the whole pWord.The second problem is that you're returning true or false after the first check so if the first letter isn't an uppercase letter then the rest of the password is ignored! Instead you need to keep a boolean variable that is returned false only if none of the letters match upperLetters.
So the whole function becomes this:
You can also avoid the flag entirely (as below), but I think the above is clearer to read and understand, and would be more useful if in the future you want to check if they have more than 1 upper case letter, for example, by keeping a counter instead of a boolean.
Just replicate these changes to the remaining functions.