0

Password Validator

You're interviewing to join a security team. They want to see you build a password evaluator for your technical interview to validate the input. Task: Write a program that takes in a string as input and evaluates it as a valid password. The password is valid if it has at a minimum 2 numbers, 2 of the following special characters ('!', '@', '#', '

#x27;, '%', '&', '*'), and a length of at least 7 characters. If the password passes the check, output 'Strong', else output 'Weak'. Input Format: A string representing the password to evaluate. Output Format: A string that says 'Strong' if the input meets the requirements, or 'Weak', if not. Sample Input: Hello@$World19 Sample Output: Strong a = ['!','@','#','
#x27;,'%','&','*'] b = ['0','1','2','3','4','5','6','7','8','9'] c = 0 d = 0 ab = input() for i in ab: if i in a: c += 1 if i in b: d += 1 if (c>1 and d>1) and (len(ab)>6): print("Strong") else: print("Weak") I could have solved it this way. is there a way with the regex method?

19th May 2021, 10:16 AM
Swapnil Kamdi
Swapnil Kamdi - avatar
2 ответов
+ 2
You have to use elif and if function, not only else and if. Or you can also nested it. #I don't know for the other cases but I think this will work a = ['!','@','#','
#x27;,'%','&','*'] b = ['0','1','2','3','4','5','6','7','8','9'] c = 0 d = 0 ab = input() for i in ab: if i in a: c += 1 elif i in b: d += 1 if (c>1 and d>1) and (len(ab)>6): print("Strong") else: print("Weak")
19th May 2021, 11:08 AM
Endalk
Endalk - avatar
0
Endalk thanks for code. My code is approved. I am eager to know the regex method to get it resolved.
19th May 2021, 12:04 PM
Swapnil Kamdi
Swapnil Kamdi - avatar