Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Self-documenting with a dictionary and 'all' function, after asserts fixing solution in Clear category for Acceptable Password VI by Splitter
def is_acceptable_password(password: str) -> bool:
conditions = {}
conditions['length is bigger than 6'] = len(password) > 6
conditions['has at least 1 digit'] = any([ch.isdigit() for ch in password])
conditions['not just digits'] = any([not ch.isdigit() for ch in password])
conditions['no word "password"'] = 'password' not in password.lower()
conditions['3 different characters'] = len(set(password)) >= 3
if len(password) > 9:
del conditions['has at least 1 digit']
del conditions['not just digits']
return all(conditions.values())
if __name__ == '__main__':
print("Example:")
print(is_acceptable_password('short'))
# These "asserts" are used for self-checking and not for an auto-testing
assert is_acceptable_password('short') == False
assert is_acceptable_password('short54') == True
assert is_acceptable_password('muchlonger') == True
assert is_acceptable_password('ashort') == False
assert is_acceptable_password('muchlonger5') == True
assert is_acceptable_password('sh5') == False
assert is_acceptable_password('1234567') == False
assert is_acceptable_password('12345678910') == True
assert is_acceptable_password('password12345') == False
assert is_acceptable_password('PASSWORD12345') == False
assert is_acceptable_password('pass1234word') == True
assert is_acceptable_password('aaaaaa1') == False
assert is_acceptable_password('aaaaaabbbbb') == False
assert is_acceptable_password('aaaaaabb1') == True
assert is_acceptable_password('abc1') == False
assert is_acceptable_password('abbcc12') == True
print("Coding complete? Click 'Check' to earn cool rewards!")
March 31, 2020
Comments: