0

password = input() import re #length 7 characters if len(password) <= 6: print ("Weak") #min 2 numbers elif re.search(r'\d{2,}',password) == None: print ("Weak") #2 special characters !@#\$%&* elif re.search(r'[!@#\$%&*]{2,}',password) == None: print ("Weak") else: print ("Strong") All test case pass except case 13. Please give some advice thank you.

3rd Jun 2020, 12:22 AM
Toh De Kai
12 ответов
+ 2
The metacharacters \d{2,} mean two or more consecutive numbers. My way of solving this was to say: ... elif len(re.findall(r"\d", password)) >= 2: In this example, findall() finds each numeric character in password, and saves it into a list. If that list has length of at least 2, it's good. 👍 Same with the special characters, obviously.
5th Jun 2020, 6:56 AM
Russ
+ 1
Your code is checking for the 2 numbers and 2 special characters to be next to each other, which is not required in the task.
4th Jun 2020, 4:44 PM
Russ
+ 1
Vijay "Always try to use minimum lines of code" - why on earth do you think this? This is not good advice to anyone, beginner or expert. You should write code so it is structured, readable and understandable. Also, your code doesn't work because it only checks for one number and one special character. password: hello3! - output strong.
3rd Sep 2020, 5:58 AM
Russ
+ 1
Why u using regular expressions Make the code more readable like mine le = input() specialchar = ['!', '@', '#', '
#x27;, '%', '&', '*'] nums = [str(i) for i in range(10)] def validator(phrase): speccount =0 numscount =0 for letter in phrase: if letter in specialchar: speccount += 1 if letter in nums: numscount +=1 if len(phrase) >= 7: if speccount >=2 and numscount>=2: print("Strong") elif speccount < 2 and numscount < 2: print("Weak") else: print("Weak") else: print("Weak") validator(le)
25th Oct 2020, 6:35 AM
Eon
0
What was the test case 13?
3rd Jun 2020, 12:39 AM
Laopigo
0
Russ how do I fix that ?
5th Jun 2020, 12:17 AM
Toh De Kai
0
U have used too many lines for solving this problem and also {2,} dictating the program to find 2 consecutive numbers and special characters in the input string. That's why case 13 displaying error. Just look my script : (Always remember try to use minimum lines of code for a particular problem.) https://code.sololearn.com/cBBy35bFf49M/?ref=app
3rd Sep 2020, 5:06 AM
Vijay
0
I have fixed that bug . So, u can check out and if you find something is missing leave a note .
3rd Sep 2020, 12:17 PM
Vijay
0
Vijay, you could even use just two lines of code if you wanted: from re import match print("Strong" if match(r"(?=.{7,})(?=(.*\d){2,})(?=(.*[!@#\$%&*]){2,})", input()) else "Weak") But, like Russ mentioned, the shortest anwser is not always the most easily understandable one. However I do like the use of lookahead and based my solution on it as well. https://code.sololearn.com/c8MG5M1hZ0ZF/?ref=app
9th Apr 2021, 5:47 PM
Khidr
0
Can anyone post the question please
31st May 2021, 4:00 PM
Nana King Obedson
0