import string
def validate_password(password):
# 문자열이 8자 이상인지 확인.
is_long = False
if len(password) >= 8 :
is_long =True
# 문자열에 숫자가 포함되어 있는지 확인
includes_digit = False
for digit in password:
if digit.isdigit():
includes_digit = True
# 문자열에 알파벳 대문자가 포함되어 있는지 확인
includes_upper = False
for char in password:
if char.isupper():
includes_upper = True
# 문자열에 알파벳 소문자가 포함되어 있는지 확인
includes_lower = False
for char in password:
if char.islower():
includes_lower = True
return is_long and includes_digit and includes_upper and includes_lower
def validate_birthday(birthday):
year, month, day = birthday
# 연도가 조건에 맞는지 확인 아니면 False를 return
if year < 1900 or year > 2018:
return False
# 달이 31일까지 있는 경우, 날짜가 유효한지 체크
if month in [1, 3, 5, 7, 8, 10, 12]:
if day< 1 or day >31 :
return False
# 달이 30일까지 있는 경우, 날짜가 유효한지 체크
elif month in [4, 6, 9, 11]:
if day <1 or day>30:
return False
# 2월인 경우, 날짜가 유효한지 체크
else:
if month == 2:
if is_leap_year(year) :
if day < 1 or day > 29:
return False
else:
if day <1 or day > 28 :
return False
else:
return False
return True
def is_leap_year(year):
# 조건 1
if year % 4 == 0 :
return True
# 조건 2
elif year % 400 == 0 :
return True
# 조건 3
elif year % 100 == 0:
return False
# 모두 아닌 경우
else:
return False
# 직접 테스트
is_password_valid = validate_password("qwQ212ty!")
print(is_password_valid)
is_birthday_valid = validate_birthday((1988, 3, 30))
print(is_birthday_valid)
is_2000_leap = is_leap_year(2000)
print(is_2000_leap)
```
'HappyCoding > happy python' 카테고리의 다른 글
Flask, 마이크로 웹 프레임워크 (0) | 2021.11.11 |
---|---|
파이썬 네이밍 컨벤션 (0) | 2021.08.19 |
PYTHON 성적 (0) | 2021.06.13 |
Python Exercise: Calculate the sum and average of n integer numbers / 사용자의 입력을 받아 평균(average) 구하기 (0) | 2021.06.13 |
도레미 파이썬. (0) | 2021.05.11 |