0

Code Coach: Password Validation

Test case #8 fails. What did I do wrong? https://code.sololearn.com/cDOO7sW7r61P/?ref=app

6th May 2020, 7:31 PM
Nafis
Nafis - avatar
11 Answers
+ 4
You have to separate special and numeric characters. Otherwise there could be numeric or special without the other. import re pswd = input() special = re.sub ("[[email protected]#$%&*]", "", pswd) nums = re.sub ("[\d]", "", pswd) if len(pswd) < 7 or len(special) == len(pswd) or len(nums) == len(pswd): print ("Weak") else : print ("Strong")
6th May 2020, 10:32 PM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar
+ 2
With re, but test 15 does not pass, I couldn't figure why: import re pas = input() if len(pas) >= 7: print('Strong' if re.search(r"[0-9]{2}", pas) and re.search(r"[[email protected]#$%&*]{2}", pas) else 'Weak') else: print('Weak') Without re, like a noob, passes all tests: num = ['0', '1', '2', '3', '4', '5', '6', '7','8', '9'] spec = ['!', '@', '#', '
#x27;, '%', '&', '*'] pas = input() if len(pas) >= 7: n = 0 s = 0 for l in pas: if l in num: n += 1 if l in spec: s += 1 if s >= 2 and n >=2: print('Strong') else: print('Weak') else: print('Weak')
20th Dec 2021, 6:21 PM
TensorFlow23
TensorFlow23 - avatar
+ 1
Post the link of your solved code here .The link you provided is of the question.
6th May 2020, 7:32 PM
Muhammad Bilal
Muhammad Bilal - avatar
+ 1
17th Mar 2021, 3:58 PM
Константин Новоселов
Константин Новоселов - avatar
+ 1
password=input() import re len_password=len(password) number=re.sub('[^1-9]','',password) len_number=len(number) simvol=re.sub('[A-Za-z-1-9]','',password) len_simvol=len(simvol) if len_password>=7 and len_number>=2 and len_simvol>=2: print('Strong') else: print('Weak')
13th May 2022, 2:29 PM
Андрей Бурвель
Андрей Бурвель - avatar
0
Muhammad Bilal Sorry, my bad.
6th May 2020, 7:36 PM
Nafis
Nafis - avatar
0
No problem post your code so that someone see your code and solve error.
6th May 2020, 7:39 PM
Muhammad Bilal
Muhammad Bilal - avatar
0
This is the correct answer! import re running = True password = input() number = re.compile(r'\d') num = number.findall(password) numb = re.compile(r'\d') n = number.findall(password) special_character = re.compile(r'[^\w\d\s]') spe_char = special_character.findall(password) if len(password) >= 7 and num != [] and spe_char != [] and numb != []: print('Strong') else: print('Weak')
9th Oct 2020, 7:29 AM
Dawit Mekonnen
Dawit Mekonnen - avatar
0
import re _main_ = 'name' password = input() # 'hello @ $ World19' def check_simbol(passw) -> object: check1 = re.findall(r'[[email protected]#$%&*]', passw) # find simbols return check1 def check_num(passw) -> object: check2 = 0 for i,s in enumerate(passw): if s.isdigit(): check2 += len(s) # count numbers return check2 if len(password) >= 7 and len(check_simbol(password)) >= 2 and check_num(password) >= 2: print('Strong') else: print('Weak')
1st Sep 2021, 8:50 PM
Johny Bracker
Johny Bracker - avatar
0
Complementing to @Manu_1-9-8-5 solution, since the "pswd = [email protected]#9" must not be Strong. Uncomment the IF to verify. import re #pswd = input() pswd = "[email protected]#9" special = re.sub ("[[email protected]#$%&*]", "", pswd) nums = re.sub ("[\d]", "", pswd) #if len(pswd) < 7 or abs(len(special)-len(pswd))<2 or abs(len(nums) - len(pswd))<2: if len(pswd) < 7 or len(special)==len(pswd) or len(nums) ==len(pswd): print ("Weak") else : print ("Strong")
21st Jan 2022, 5:32 AM
Antonio Rojas
Antonio Rojas - avatar
0
password= input() num = 0 v = 0 L=[] s = ['!', '@', '#', '
#x27;, '%', '&', '*'] for c in password: if(c.isnumeric()): num+=1 L.append(c in s) v= L.count(True) if(num>=2 and v >=2 and len(password)>=7): print("Strong") else: print("Weak")
19th Mar 2022, 7:09 PM
Alex