Reputation: 11
I've broken down the pieces of this code individually and it all works fine. Yet the append() method only appends once and then refuses to add anything else. I am absolutely losing my mind over this.
x = input("Input Password: ")
epicfail = []
def numberchecker(b):
return any(i.isdigit() for i in b)
def spacechecker(c):
return any(o.isspace() for o in c)
def passwordvalidator(a):
if len(a) < 12:
epicfail.append("Your password is too short!")
elif a.islower() == True:
epicfail.append("Your password contains zero uppercase letters!")
elif a.isupper() == True:
epicfail.append("Your password contains zero lowercase letters!")
elif numberchecker(x) == False:
epicfail.append("Your password contains zero numbers!")
elif spacechecker(x) == True:
epicfail.append("Your password contains a whitespace!")
return epicfail
print(passwordvalidator(x))
I expect the append() method to append to the epicfail list every time it is activated. Yet is only appends once. I have tried breaking down every piece of the code individually and it all works fine.
Upvotes: 0
Views: 66
Reputation: 316
As you use elif
, when one condition is met, all the others are ignored. If you want multiple to trigger, just use if
instead.
Furthermore, you can remove "== True" when you are checking a boolean, and replace "if xxx == False:" by "if not xxx:".
Upvotes: 1