0
Password Validation
https://code.sololearn.com/c7r247tcwo2Y/?ref=app Correct me for error
4 ответов
+ 1
Sry for late . May it already solved. But adding my correction :
Corrected code, making strings of integers instead of int comparisions, because according your logic ,it is simple way...
#
pattern1 = ["!","@","#","quot;,"%","&","*"]
pattern2 = list(map(str,range(0,10))) #making list to string of digits..
password=input()
def func_count(password ,x):
d=0
for i in password :
if i in x: # using in here,
d+=1
return d
#for pattern1 in password :
count1=func_count(password ,pattern1 )
#for pattern2 in password :
count2=func_count(password ,pattern2 )
if count1>=2 and count2 >=2 and len(password)>=7:
print ('Strong')
else :
print ('Weak')
print (count1 )
print (count2 )
print (len(password ))
+ 2
How take int as input for pattern 2. Done changes suggested, but getting results always 'weak'
+ 1
pattern1 = ["!","@","#","quot;,"%","&","*"]
pattern2 = range(0,10) #pattern2 now here stores an iterator. not a list of unpacked numbers from 0 to 10 . and its numbers is in form of integer but when you checking in loop, there your having charecter like '1' , not 1.
password=input()
def func(x):
d=0
for i in password :
if i==x: #this means char==list, false always.. may i in x works for pattern1 only.. for pattern2, as already told it comparing like string: '1' in integers of range(0,10) so always false. you should need int(i) in x for pattern2
d+=1
return d #ident this out of loop
#these 2 statement have no use , you are not storing returned values and using again in if condition hence no need.
#func(pattern 1)
#func(pattern2 )
if func (pattern1 )>=2 and func (pattern2 )>=2 and len(password)>=7:
print ('Strong')
else :
print ('Weak')
so because of wrong check in i==x , tjis cide failing....
hope it helps to correct it...
0
password = list(input())
str = " ".join(password) #a string with space b/w the items
import re
symb = re.findall("[!@#\$%&\*]+", str)
num = re.findall(r"[0-9]+", str)
filt = filter((lambda x: x in symb,str), (password))
print ("Strong" if len(symb) >= 2 and len(num) >= 2 and len(password) >=7 else "Weak")