[SOLVED] Help me solve this... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

[SOLVED] Help me solve this...

You're interviewing to join a security team. They want to see you build a password evaluator for your technical interview to validate the input. Task: Write a program that takes in a string as input and evaluates it as a valid password. The password is valid if it has at a minimum 2 numbers, 2 of the following special characters ('!', '@', '#', '

#x27;, '%', '&', '*'), and a length of at least 7 characters. If the password passes the check, output 'Strong', else output 'Weak'. Input Format: A string representing the password to evaluate. Output Format: A string that says 'Strong' if the input meets the requirements, or 'Weak', if not. Sample Input: Hello@$World19 Sample Output: Strong My attempt:- https://code.sololearn.com/cNMR5d7EGcgI/?ref=app

21st Jan 2021, 2:55 PM
‎Keshav
‎Keshav - avatar
10 Answers
+ 10
#MyCode string = input() num_count = 0 char_count = 0 char = ["!","@","#","
quot;,"%","&","*"] nums = ["1","2","3","4","5","6","7","8","9","0"] for var in string: if var in char: char_count += 1 if var in nums: num_count += 1 if (char_count>1 and num_count>1) and (len(string)>6): print("Strong") else: print("Weak")
21st Jan 2021, 3:56 PM
Hacker Badshah
Hacker Badshah - avatar
+ 4
Your code will always output Weak as "in" operater checks only one value in a sequence and can't be mixed with "and" to check multiple values. Hope It Helps You 😊
21st Jan 2021, 3:36 PM
Hacker Badshah
Hacker Badshah - avatar
+ 2
Hacker Badshah Oh thanks I understood the logic too I'll write this code on my own now. Thanks for the help, buddy 👍
21st Jan 2021, 4:08 PM
‎Keshav
‎Keshav - avatar
+ 1
Can it be done using regex
19th May 2021, 9:54 AM
Swapnil Kamdi
Swapnil Kamdi - avatar
+ 1
Swapnil Kamdi You asking or telling me? 😅😅
19th May 2021, 10:26 AM
‎Keshav
‎Keshav - avatar
+ 1
‎Kêsh@v Obviously asking, I forgot to put question mark. I'm looking a code for this in regex method. Would you please help me out.
19th May 2021, 12:07 PM
Swapnil Kamdi
Swapnil Kamdi - avatar
+ 1
nums='0123456789' sp_characters='!@#$%&*' password=str(input()) a=0 b=0 for i in range(len(sp_characters)): for x in range(len(password )): if sp_characters [i]==password[x]: a+=1 for i in range(len(nums)): for x in range(len(password)): if nums[i]==password[x]: b+=1 if a>=2 and b>=2 and len(password)>=7: print('Strong') else: print('Weak')
25th Oct 2021, 9:28 PM
youssef
youssef - avatar
0
Swapnil Kamdi I don't know bcz I've never practiced Regex :(
19th May 2021, 12:35 PM
‎Keshav
‎Keshav - avatar
0
#Swift #swift var myString = readLine() ?? "" var ch_ = ["!", "@", "#", "
quot;, "%", "&", "*"] var sm_ = ["0","1","2","3","4","5","6","7","8","9"] var ch = 0 var sm = 0 for i in myString{ if ch_.contains("\(i)"){ ch+=1 }else if sm_.contains("\(i)"){ sm+=1} } if sm>=2 && ch>=2 && myString.count>=7{ print("Strong") }else{ print("Weak") }
11th Oct 2022, 9:55 AM
Artem Leschenko
Artem Leschenko - avatar
0
# my solution # python password = input() mot = len(password ) nb = ("0123456789") special_caract = ('!', '@', '#', '
#x27;, '%', '&', '*') n=0 s=0 for i in password : if i in nb : n+=1 elif i in special_caract : s+= 1 if n>1 and s >1 and mot >6: print ("Strong") else : print ("Weak")
11th May 2023, 8:34 AM
Oussama Kadimallah
Oussama Kadimallah - avatar