This is the criteria:
Its length is at least 6. It contains at least one digit. It contains at least one lowercase English character. It contains at least one uppercase English character. It contains at least one special character. The special characters are: !@#$%^&*()-+
My code is working for all test cases but I'm afraid it seems way longer than necessary. I'm trying to trim it down.
import math
import os
import random
import re
import sys
# Complete the minimumNumber function below.
def minimumNumber(n, password):
# Return the minimum number of characters to make the password strong
flag = 0
if len(password) >= 6:
passRegex = re.compile(r"^(?=.*[\d])")
mo = passRegex.search(password)
if mo is None:
flag+=1
passRegex = re.compile(r"^(?=.*[A-Z])")
mo = passRegex.search(password)
if mo is None:
flag+=1
passRegex = re.compile(r"^(?=.*[a-z])")
mo = passRegex.search(password)
if mo is None:
flag+=1
passRegex = re.compile(r'[!@#$%^&*()-+]')
mo = passRegex.search(password)
if mo is None:
flag+=1
return flag
else:
if any(x in "0123456789" for x in password) is False:
flag+=1
if any(x in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for x in password) is False:
flag+=1
if any(x in "abcdefghijklmnopqrstuvwxyz" for x in password) is False:
flag+=1
if any(x in "!@#$%^&*()-+" for x in password) is False:
flag+=1
if (flag+len(password)<6):
return 6-len(password)
if (flag+len(password)>=6):
return flag
if __name__ == '__main__':
n = int(input())
password = input()
answer = minimumNumber(n, password)
Any advice is appreciated.