Q70. 오늘의 년/월/일과 출생의 년/월/일을 입력받아 만 나이를 계산하는 프로그램을 작성하시오.
▶ 만 나이 계산 알고리즘(오늘 현재를 2019년 10월 17일로 가정)
- 출생 월이 1~ 9월인 경우
만 나이 = 2019 - 출생 년
- 출생 월이 10인 경우
. 출생 일이 1~19일 인 경우
만 나이 = 2019 - 출생 년
. 출생 일이 20 ~ 인 경우
만 나이 = 2019 - 출생 년 - 1
- 출생 월이 11~ 이후인 경우
만 나이 = 2019 - 출생 년 - 1
(300점)
print("=" * 50)
now_year = int(input("현재년을 입력해 주세요 : "))
now_month = int(input("현재월을 입력해 주세요 : "))
now_day = int(input("현재일을 입력해 주세요 : "))
birth_year = int(input("출생년을 입력해 주세요 : "))
birth_month = int(input("출생월을 입력해 주세요 : "))
birth_day = int(input("출생일을 입력해 주세요 : "))
_____ birth_month < now_month :
age = now_year - birth_year
_____ birth_month == now_month :
______ birth_day <= now_day :
age = now_year - birth_year
______ :
age = now_year - birth_year - 1
______ :
age = now_year - birth_year - 1
print("=" * 50)
print("오늘 날짜 : %d년 %d월 %d일" % (now_year, now_month, now_day))
print("생년 월일 : %d년 %d월 %d일" % (birth_year, birth_month, birth_day))
print("-" * 50)
print("만 나이 : ______세" % ______)
print("=" * 50)
- 난이도(1~10) : 3
- 힌트 : 없음
- - 실행 결과
-
==================================================
현재년을 입력해 주세요 : 2019
현재월을 입력해 주세요 : 10
현재일을 입력해 주세요 : 17
출생년을 입력해 주세요 : 1997
출생월을 입력해 주세요 : 4
출생일을 입력해 주세요 : 9
==================================================
오늘 날짜 : 2019년 10월 17일
생년 월일 : 1997년 4월 9일
--------------------------------------------------
만 나이 : 22세
==================================================
print("=" * 50)
now_year = int(input("현재년을 입력해 주세요 : "))
now_month = int(input("현재월을 입력해 주세요 : "))
now_day = int(input("현재일을 입력해 주세요 : "))
birth_year = int(input("출생년을 입력해 주세요 : "))
birth_month = int(input("출생월을 입력해 주세요 : "))
birth_day = int(input("출생일을 입력해 주세요 : "))
if birth_month < now_month :
age = now_year - birth_year
elif birth_month == now_month :
if birth_day <= now_day :
age = now_year - birth_year
else :
age = now_year - birth_year - 1
else :
age = now_year - birth_year - 1
print("=" * 50)
print("오늘 날짜 : %d년 %d월 %d일" % (now_year, now_month, now_day))
print("생년 월일 : %d년 %d월 %d일" % (birth_year, birth_month, birth_day))
print("-" * 50)
print("만 나이 : %d세" % age)
print("=" * 50)