Password Rules

Password Rules

Medium Programming Interview OOP 27 views
Explanation Complexity

Problem Statement

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.

Output Format

YES or NO.

Example

Abcdef12
YES

Constraints

Length

Input / Output Format

Input Format
One line password.
Output Format
YES or NO.
Constraints
Length

Examples

Input:
Abcdef12
Output:
YES

Example Solution (Public)

Programming Interview
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')

Official Solution Code

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')
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.