본문 바로가기

Python_Matter/[Check_IO]ElectronicStation

Acceptable Password V

AnKiWoong 2020. 4. 22. 20:25
반응형
(追記) (追記ここまで)

Quiz>

In this mission you need to create a password verification function.

Those are the verification conditions:

the length should be bigger than 6;

should contain at least one digit, but it cannot consist of just digits;

having numbers or containing just numbers does not apply to the password longer than 9.

a string should not contain the word "password" in any case.

Input:

A string.

Output:

A bool.

Example:

is_acceptable_password('short') == False
is_acceptable_password('short54') == True
is_acceptable_password('muchlonger') == True
is_acceptable_password('ashort') == False
is_acceptable_password('muchlonger5') == True
is_acceptable_password('sh5') == False
is_acceptable_password('1234567') == False
is_acceptable_password('12345678910') == True
is_acceptable_password('password12345') == False
is_acceptable_password('PASSWORD12345') == False
is_acceptable_password('pass1234word') == True

How it’s used:

For password verification form. Also it's good to learn how the task can be evaluated.

# Taken from mission Acceptable Password IV
def is_acceptable_password(password: str):
 # 조건 1 : 길이는 6보다 커야합니다.
 condition_one = len(password) > 6
 # 조건 2 : 하나 이상의 숫자를 포함해야하지만 숫자만으로는 구성 할 수 없습니다.
 condition_two = any(map(str.isdigit, password)) and not password.isdigit()
 # 조건 3 : 숫자가 있거나 숫자만 포함하는 것은 9보다 긴 암호에는 적용되지 않습니다.
 condition_three = len(password) > 9
 # 모든 조건을 비교해서 반환
 # A and B
 # A, B 둘 다 참이면 B 를 출력
 # A, B 둘 다 거짓이면 A 를 출력
 # A, B 둘 중에 하나만 참이면 거짓인 값을 출력
 # A or B
 # A, B 둘 다 참이면 A 를 출력
 # A, B 둘 다 거짓이면 B 를 출력
 # A, B 둘 중에 하나만 참이면 참인 값을 출력
 return condition_one and (condition_two or condition_three)
def is_acceptable_password(a):
 # your code here
 return None
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
 print("Coding complete? Click 'Check' to earn cool rewards!")

Solve>

1. 조건 1 : 길이는 6보다 커야합니다.

def is_acceptable_password(a):
 condition_one = len(a) > 6

2. 조건 2 : 하나 이상의 숫자를 포함해야하지만 숫자만으로는 구성 할 수 없습니다.

def is_acceptable_password(a):
 condition_two = any(map(str.isdigit, a)) and not a.isdigit()

3. 조건 3 : 숫자가 있거나 숫자 만 포함하는 것은 9보다 긴 암호에는 적용되지 않습니다.

def is_acceptable_password(a):
 condition_three = len(a) > 9

4. 조건 4 : 문자열은 "password"라는 단어를 포함해서는 안됩니다

def is_acceptable_password(a):
 condition_four = 'password' not in a.lower()

5. 모든 조건을 비교해서 반환

5-1. A and B

5-2.A, B 둘 다 참이면 B 를 출력

5-3. A, B 둘 다 거짓이면 A 를 출력

5-4. A, B 둘 중에 하나만 참이면 거짓인 값을 출력

5-5. A or B

5-6. A, B 둘 다 참이면 A 를 출력

5-7. A, B 둘 다 거짓이면 B 를 출력

5-8. A, B 둘 중에 하나만 참이면 참인 값을 출력

def is_acceptable_password(a):
 return condition_one and (condition_two or condition_three) and condition_four

Code>

def is_acceptable_password(a):
 condition_one = len(a) > 6
 condition_two = any(map(str.isdigit, a)) and not a.isdigit()
 condition_three = len(a) > 9
 condition_four = 'password' not in a.lower()
 
 return condition_one and (condition_two or condition_three) and condition_four

Example>

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
 print("Coding complete? Click 'Check' to earn cool rewards!")

Result>

Example:

False

Coding complete? Click 'Check' to earn cool rewards!

반응형
(追記) (追記ここまで)
(追記) (追記ここまで)

'Python_Matter > [Check_IO]ElectronicStation' 카테고리의 다른 글

Acceptable Password VI (0) 2020年04月22日
Acceptable Password IV (0) 2020年04月22日
Acceptable Password III (0) 2020年04月22日
Acceptable Password II (0) 2020年04月21日

DESIGN BY TISTORY 관리자
Total = 852,520명 | Today = 0명 | Yesterday = 70명

티스토리툴바

AltStyle によって変換されたページ (->オリジナル) /