+ 2
When we give solution to a coding problem , why 1 out of 13 case fails ?
Why do the single test case not work with same piece of code rest are working? Here is password validator program link https://www.sololearn.com/coach/76?ref=app Which according to me is perfectly fine But it is not working for test case 8? Can anyone please let me know why?
15 Answers
+ 6
The link you provided leads to the code coach itself.
+ 6
Prince Yadav, just store your attempt in a code in Playground and link it here, then we'll take a look at the problem.
Or you copypaste it here, since they're generally short.
Lynx, giving him *your* solution will not help him understand *his* mistake.
+ 2
Ok sorry for it
+ 2
Your result comes out as strong even if you have less than 2 of the symbols in it.
+ 1
Doesn't isa(n) always return True ?
+ 1
Lynx no it returns 1 when the character match with 7 special characters
+ 1
'if x or y or z' doesn't mean what you think it means.
It means:
if x is truthy or y is truthy or z is truthy.
Every string that's not empty ('') is truthy, so that function indeed always returns 1.
You probably want to find out if n is one of the symbols.
One pattern you can use:
if n in (x, y, z):
...
+ 1
Prince Yadav line 27. Just add "or x<2"
0
#password validator
a=input()
def isd(n):
if ord(n)<58 and ord(n)>47:
return 1
return 0
def isa(n):
if '!' or '&' or '*' or '#' or '#x27; or '%' or '@':
return 1
return 0
def lv(a):
b=len(a)
if b>=7:
return 1
return 0
def pv(a):
if not lv(a) :
return 0
z=0
x=0
for i in a:
if i==' ':
return 0
if isd(i):
z+=1
if isa(i):
x+=1
if z<2:
return 0
return 1
if pv(a):
print ('Strong')
else :
print ('Weak')
0
HonFu
As you suggested, I made a change in my code
Link: https://code.sololearn.com/cb8GAiZf7k6N/?ref=app
Still it is failing in test case 8
0
I think the error is not inside special character validator fxn
It's somewhere else
Please help me
0
Prince Yadav you still have to check if there more than 2 special chars.
0
Thanks to all
Now it is working
0
This is an approach
import re
def password_validation(password):
numbers = re.findall(r'[0-9]', password)
specialChars = re.findall(r'\W', password)
if len(password) > 6 and len(numbers) > 1 and len(specialChars) > 1:
return 'Strong'
return 'Weak'
print(password_validation(input()))