My name is Edwin i am new to programming but i love to learn. I have a assignment for school and i must build a program that rates passwords. but i have a litle problem now. As you can see i made 3 lists with every character. If i run this program it will not show "uw wachtwoord is Sterk" if the conditions klein and groot and nummers and symbols are true. how do i fix this?
btw i can't make use of isdigit,isnumeric and such.
thank you in advance!
print ("Check of uw wachtwoord veilig genoeg is in dit programma.")
print ("Uw wachtwoord moet tussen minimaal 6 en maximaal 12 karakters
bestaan")
print ("U kunt gebruik maken van hoofdletters,getallen en symbolen
(@,#,$,%)")
ww = input("Voer uw wachtwoord in: ")
klein = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm','n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
groot = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
nummers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
symbolen= [' ', '!', '#', '$', '%', '&', '"', '(', ')', '*', '+', ',', '-',
'.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`',
'{', '|', '}', '~',"'"]
if len(ww) < 6:
print ("uw wachtwoord is te kort, uw wachtwoord moet uit minimaal 6 en
maximaal 12 karakters bestaan!")
elif len(ww) > 12:
print ("uw wachtwoord is te lang, uw wachtwoord moet uit minimaal 6 en
maximaal 12 karakters bestaan!")
elif len(ww) >= 6 and len(ww)<= 12:
if ww == klein and ww == groot and ww == nummers and ww == symbolen:
print ("uw wachtwoord is Sterk")
Your test cannot work because you're comparing your password (of type
str
: string) against alist
. Since objects are non-comparable, the result is justFalse
(even if they were comparable there is no equality here, but a non-empty intersection to check)You need to check for each list that there's at least 1 member of the list in the password
Define an aux function which checks if a letter of the list is in the password (a lambda would be too much maybe) using
any
:Then test all your four lists against this condition using
all
:Note the slight optimization by converting the password (which is kind of a list so O(n) for
in
operator) by aset
of characters (where thein
operator exists but is way faster). Besides, a set will remove duplicate characters, which is perfect for this example.More compact version without the aux function and using a
lambda
which is not so difficult to understand after all: