0
Code Coach: Password Validation
Test case #8 fails. What did I do wrong? https://code.sololearn.com/cDOO7sW7r61P/?ref=app
12 Respostas
+ 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 ("[!@#$%&*]", "", 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")
+ 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"[!@#$%&*]{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')
+ 1
Post the link of your solved code here .The link you provided is of the question.
+ 1
My solution without using re
https://code.sololearn.com/cw80ctatk41c/?ref=app
+ 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')
0
Muhammad Bilal Sorry, my bad.
0
No problem post your code so that someone see your code and solve error.
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')
0
import re
_main_ = 'name'
password = input() # 'hello @ $ World19'
def check_simbol(passw) -> object:
check1 = re.findall(r'[!@#$%&*]', 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')
0
Complementing to @Manu_1-9-8-5 solution, since the "pswd = Hello@World#9" must not be Strong. Uncomment the IF to verify.
import re
#pswd = input()
pswd = "Hello@World#9"
special = re.sub ("[!@#$%&*]", "", 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")
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")
0
#include <iostream>
#include <string>
using namespace std;
class password{
private:
string str;
public:
void getpassword();
bool evaluatepassword();
void result(bool x);
};
int main(){
password pass;
pass.getpassword();
pass.result(pass.evaluatepassword());
return 0;
}
void password::getpassword(){
getline(cin,str);
}
void password::result(bool x){
if (x)
cout<<"Strong";
else
cout<<"Weak";
}
bool password::evaluatepassword(){
int sc{0},minnumc{0};
if(str.length()>=7){
for(char c : str){
if(c=='!'||c=='@'||c=='#'||c=='#x27;||c=='%'||c=='*')
sc++;
if(c>='1'&&c<='9')
minnumc++;
}
if(sc>=2&&minnumc>=2)
return true;
else
return false;
}
else
return false;
}
what's wrong with this code??