1. 문제
나이를 입력하면 몇년 후에 내가 100살인지 계산.
2. 사용함수
.isdigit() : 숫자면 True, 아니면 False
datetime.datetime.today() : 오늘 날짜 출력
today.year : 해당 연도 출력
3. 실행
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
import datetime
today = datetime.datetime.today()
age = input('나이를 입력하시오:')
if age.isdigit():
myHundred = 100 - int(age)
afterYear = today.year + myHundred
else:
print('잘못입력했음')
print('{}년({}년후)에 당신의 나이는 100살입니다.'.format(afterYear, myHundred))
|
cs |
4. 결과물
'Coding test > Python 기초문제' 카테고리의 다른 글
[for 반복문] 합, 짝수합, 홀수합, 팩토리얼 구하기 (0) | 2022.04.27 |
---|---|
[%, // 연산자] 빵과 우유 배분하기 (0) | 2022.04.17 |
[for 반복문] 복리 계산기 (0) | 2022.04.17 |
[if/elif 조건문] 성적표 출력하기 (1) | 2022.04.16 |
[while 반복문] 거스름돈 계산기 (0) | 2022.04.16 |