-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrong password.py
95 lines (63 loc) · 2.48 KB
/
Strong password.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#Louise joined a social networking site to stay in touch with her friends. The signup page required her to input a name and a password. However, the password must be strong. The website considers a password to be strong if it satisfies the following criteria:
# Its length is at least
.
# 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: !@#$%^&*()-+
#She typed a random string of length
#in the password field but wasn't sure if it was strong. Given the string she typed, can you find the minimum number of characters she must add to make her password strong?
#Note: Here's the set of types of characters in a form you can paste in your solution:
#numbers = "0123456789"
#lower_case = "abcdefghijklmnopqrstuvwxyz"
#upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#special_characters = "!@#$%^&*()-+"
#Input Format
#The first line contains an integer
#denoting the length of the string.
#The second line contains a string consisting of
#characters, the password typed by Louise. Each character is either a lowercase/uppercase English alphabet, a digit, or a special character.
#Constraints
#Output Format
#Print a single line containing a single integer denoting the answer to the problem.
#Sample Input 0
#3
#Ab1
#Sample Output 0
#3
#Explanation 0
#She can make the password strong by adding
#characters, for example, $hk, turning the password into Ab1$hk which is strong.
#characters aren't enough since the length must be at least
#Sample Input 1
#11
##HackerRank
#Sample Output 1
#1
#Explanation 1
#The password isn't strong, but she can make it strong by adding a single digit.
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
count = 0
if any(i.isdigit() for i in password)==False:
count+=1
if any(i.islower() for i in password)==False:
count+=1
if any(i.isupper() for i in password)==False:
count+=1
if any(i in special_characters for i in password)==False:
count+=1
return max(count,6-n)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
password = input()
answer = minimumNumber(n, password)
fptr.write(str(answer) + '\n')
fptr.close()