Skip to content

Commit 47d3776

Browse files
Added solution
1 parent f574230 commit 47d3776

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

amazon/strong_password.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
10+
'''
11+
It contains at least one special character. The special characters are: !@#$%^&*()-+
12+
'''
13+
14+
# Complete the minimumNumber function below.
15+
def minimumNumber(n, password):
16+
# Return the minimum number of characters to make the password strong
17+
numbers = "0123456789"
18+
lower_case = "abcdefghijklmnopqrstuvwxyz"
19+
upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
20+
special_characters = "!@#$%^&*()-+"
21+
22+
def checkNumbers(pwd):
23+
if not pwd: return 0
24+
return any(char.isdigit() for char in pwd)
25+
return 0
26+
27+
def checkLower(pwd):
28+
if not pwd: return 0
29+
return any(char.islower() for char in pwd)
30+
return 0
31+
32+
def checkUpper(pwd):
33+
if not pwd: return 0
34+
return any(char.isupper() for char in pwd)
35+
return 0
36+
37+
def checkSpecial(pwd):
38+
if not pwd: return 0
39+
return any(char in special_characters for char in pwd)
40+
return 0
41+
42+
count = 0
43+
if not checkSpecial(password):
44+
count += 1
45+
if not checkLower(password):
46+
count += 1
47+
if not checkUpper(password):
48+
count +=1
49+
if not checkNumbers(password):
50+
count += 1
51+
return max(count, 6 - n)
52+
53+
if __name__ == '__main__':
54+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
55+
56+
n = int(input())
57+
58+
password = input()
59+
60+
answer = minimumNumber(n, password)
61+
62+
fptr.write(str(answer) + '\n')
63+
64+
fptr.close()

0 commit comments

Comments
 (0)