본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 33

반응형

Q>

사용자에게 암호를 입력받아 사용 가능 / 불가능 여부를 판단하시오.

암호 조건

- 중복되는 숫자 불가능

- 4자리 모두 1씩 증가되면 안된다.

- 4자리 모두 1씩 감소되면 안된다.


A>

password = input("사용하고자 하는 암호를 입력하세요: ")

p1 = int(password[0])
p2 = int(password[1])
p3 = int(password[2])
p4 = int(password[3])

duplicate = p1 == p2 or p1 == p3 or p1 == p4 or p2 == p3 or p2 == p4 or p3 == p4
increment = p1 + 1 == p2 and p2 + 1 == p3 and p3 + 1 == p4
decrement = p1 - 1 == p2 and p2 - 1 == p3 and p3 - 1 == p4

if duplicate or increment or decrement:
print("사용할 수 없는 암호입니다.")
else:
print("사용할 수 있는 암호입니다.")

사용하고자 하는 암호를 입력하세요: 2163

사용할 수 있는 암호입니다.


Process finished with exit code 0


사용하고자 하는 암호를 입력하세요: 1234

사용할 수 없는 암호입니다.


Process finished with exit code 0

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 35  (0) 2019.05.25
Python Learn the basics Quiz 34  (0) 2019.05.12
Python Learn the basics Quiz 32  (0) 2019.05.12
Python Learn the basics Quiz 31  (0) 2019.05.02
Python Learn the basics Quiz 30  (0) 2019.05.02