Skip to content

Commit 1a9a0fd

Browse files
Create Strong Password
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.
1 parent 7b8f180 commit 1a9a0fd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Strong Password

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/python
2+
3+
import sys
4+
5+
def minimumNumber(n, password):
6+
numbers = "0123456789"
7+
lower_case = "abcdefghijklmnopqrstuvwxyz"
8+
upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
9+
special_characters = "!@#$%^&*()-+"
10+
11+
count = 0
12+
if any(i.isdigit() for i in password) == False:
13+
count += 1
14+
if any(i.islower() for i in password) == False:
15+
count += 1
16+
if any(i.isupper() for i in password) == False:
17+
count += 1
18+
if any(i in special_characters for i in password) == False:
19+
count+=1
20+
return max(count,6-n)
21+
22+
if __name__ == "__main__":
23+
n = int(raw_input().strip())
24+
password = raw_input().strip()
25+
answer = minimumNumber(n, password)
26+
print answer
27+

0 commit comments

Comments
 (0)