+ 1
(Py) Password Validation exercise
Failing only 1 test case and not sure why. Code: import re pword = input() pattern = r'[!@#$%&*]{2,}' if len(pword) < 7: print("Weak") elif re.search(r'\d+\d+',pword): if re.search(pattern,pword): print("Strong") else: print("Weak") else: print("Weak")
2 Answers
+ 2
Better to use this.
No need to use re module
chars =['!', '@', '#', '#x27;, '%', '&', '*']
userStr = input()
numbChar=0
numbLett=0
numbInt=0
#get the requirements
for char in userStr:
if char in chars:
numbChar+=1
elif char.isdigit():
numbInt+=1
elif char.isalpha():
numbLett+=1
if numbChar >=2 and numbInt >= 2 and len(userStr) >= 7:
print("Strong")
else:
print("Weak")
- 3
no