[Python] Checkio Solution 解答 – House Password

架網編程

Problem:

Stephan and Sophia forget about security and use simple passwords for everything. Help Nikola develop a password security check module. The password will be considered strong enough if its length is greater than or equal to 10 symbols, it has at least one digit, as well as containing one uppercase letter and one lowercase letter in it. The password contains only ASCII latin letters or digits.

 

Level:

Elementary

 

Input:

A password as a string (Unicode for python 2.7).

 

Output:

Is the password safe or not as a boolean or any data type that can be converted and processed as a boolean. In the results you will see the converted results.

 

Precondition:

re.match("[a-zA-Z0-9]+", password)
0 < len(password) ≤ 64

 

Source: https://py.checkio.org


My Solution:

def checkio(data): 
  import string 
  def have_digit(data): 
    for dig in string.digits: 
      if dig in data: 
        return True 
        break 
    else: 
      return False 
  def have_lower(data): 
    for lower in string.ascii_lowercase: 
      if lower in data: 
        return True 
        break 
    else: 
      return False 
  def have_upper(data): 
    for upper in string.ascii_uppercase: 
      if upper in data: 
        return True 
        break 
    else: 
      return False 
  def have_10(data): 
    if len(data) >= 10: 
      return True 
    else: 
      return False 
  if have_digit(data) and have_lower(data) and have_upper(data) and have_10(data): 
    return True 
  else: 
    return False

Comment:

For what I remember, this should be the first time I used string module on Checkio. The solution is kind of long but it contains several similar function definitions, which make the following if statement easier to be handled.

發佈日期:2017年9月10日 | 作者:橘小佑

Copyright © Vantopics