From 10db36a2f823f5027549e225ba1f235e33e1ab4b Mon Sep 17 00:00:00 2001 From: Megha Garg <43913641+miss-jain-16@users.noreply.github.com> Date: Mon, 25 Oct 2021 17:22:48 +0530 Subject: [PATCH] Update strong-password.py update function --- algorithms/strong-password.py | 43 +++++++++++++++-------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/algorithms/strong-password.py b/algorithms/strong-password.py index efb8070..15ab15e 100644 --- a/algorithms/strong-password.py +++ b/algorithms/strong-password.py @@ -1,9 +1,5 @@ #!/bin/python3 -import math -import os -import random -import re import sys numbers = "0123456789" @@ -12,33 +8,30 @@ special_characters = "!@#$%^&*()-+" def minimumNumber(n, password): - res = 0 - - if not any(x in numbers for x in password): - res += 1 - - if not any(x in lower_case for x in password): - res += 1 - - if not any(x in upper_case for x in password): - res += 1 + numbers = "0123456789" + lower_case = "abcdefghijklmnopqrstuvwxyz" + upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + special_characters = "!@#$%^&*()-+" - if not any(x in special_characters for x in password): - res += 1 + res = 0 - if len(password) < 6: - return max(res, 6 - len(password)) - - return res + n_bool = 1 + l_bool = 1 + u_bool = 1 + s_bool = 1 + for c in password: + if c in numbers: n_bool = 0 + elif c in lower_case: l_bool = 0 + elif c in upper_case: u_bool = 0 + elif c in special_characters: s_bool = 0 + return max(6-n, n_bool + l_bool + u_bool + s_bool) if __name__ == '__main__': - fptr = open(os.environ['OUTPUT_PATH'], 'w') + - n = int(input()) + n = int(input().strip()) password = input() answer = minimumNumber(n, password) - - fptr.write(str(answer) + '\n') - fptr.close() + print(answer)