Password Rules
Programming Interview
Medium
9 views
Problem Description
You're given {x}. Create Validator class ok() that checks: length>=8, has at least one digit, one uppercase, one lowercase. Output YES or NO.
Input Format
One line password.
Official Solution
import sys
pw=sys.stdin.read().strip()
if pw is None: sys.exit(0)
class Validator:
def __init__(self,pw):
self.pw=pw
def ok(self):
if len(self.pw)<8:
return False
hasD=False
hasU=False
hasL=False
for ch in self.pw:
o=ord(ch)
if 48<=o<=57:
hasD=True
elif 65<=o<=90:
hasU=True
elif 97<=o<=122:
hasL=True
return hasD and hasU and hasL
print('YES' if Validator(pw).ok() else 'NO')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!