Q>
Computer date and time format consists only of numbers, for example: 21.05.2018 16:30
Humans prefer to see something like this: 21 May 2018 year, 16 hours 30 minutes
Your task is simple - convert the input date and time from computer format into a "human" format.
(컴퓨터 날짜 및 시간 형식은 숫자로만 구성됩니다 (예 : 21.05.2018 16:30). 인간은 다음과 같은 것을 선호합니다 : 2018 년 5 월 21 일, 16 시간 30 분 귀하의 작업은 간단합니다 - 입력 날짜와 시간을 컴퓨터 형식에서 "인간"형식으로 변환하십시오.)
Input: Date and time as a string
(날짜 및 시간을 문자열)
Output: The same date and time, but in a more readable format
(같은 날짜와 시간이지만 더 읽기 쉬운 형식으로)
Example:
date_time("01.01.2000 00:00") == "1 January 2000 year 0 hours 0 minutes"
date_time("19.09.2999 01:59") == "19 September 2999 year 1 hour 59 minutes"
date_time("21.10.1999 18:01") == "21 October 1999 year 18 hours 1 minute"
NB: words "hour" and "minute" are used only when time is 01:mm (1 hour) or hh:01 (1 minute).
In other cases it should be used "hours" and "minutes".
How it is used: To improve the understanding between computers and humans.
(컴퓨터와 인간 사이의 이해를 향상시킵니다.)
Precondition:
0 < date <= 31
0 < month <= 12
0 < year <= 3000
0 < hours < 24
0 < minutes < 60
A>
# datetime : 날짜와 시간을 함께 저장하는 패키지
from datetime import datetime
def date_time(time):
# datetime.strptime : 현재일의 년월일을 문자열로 구한다
t = datetime.strptime(time, '%d.%m.%Y %H:%M')
# datetime.strftime : 포맷 문자열에 의해 제어되는 날짜와 시간을 나타내는 문자열을 반환
y, m, d, h, mi = t.year, datetime.strftime(t, '%B'), t.day, t.hour, t.minute
suffix = lambda n: 's' if n != 1 else ''
return f'{d} {m} {y} year {h} hour{suffix(h)} {mi} minute{suffix(mi)}'
if __name__ == '__main__':
print("Example:")
print(date_time('01.01.2000 00:00'))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert date_time("01.01.2000 00:00") == "1 January 2000 year 0 hours 0 minutes", "Millenium"
assert date_time("09.05.1945 06:30") == "9 May 1945 year 6 hours 30 minutes", "Victory"
assert date_time("20.11.1990 03:55") == "20 November 1990 year 3 hours 55 minutes", "Somebody was born"
print("Coding complete? Click 'Check' to earn cool rewards!")
O>
"Run" is good. How is "Check"?
Process finished with exit code 0
S>
'Python_Matter > Solve' 카테고리의 다른 글
Python Learn the basics Quiz 113 (0) | 2019.07.03 |
---|---|
Python Learn the basics Quiz 112 (0) | 2019.07.02 |
Python Learn the basics Quiz 110 (0) | 2019.07.02 |
Python Learn the basics Quiz 109 (0) | 2019.06.28 |
Python Learn the basics Quiz 108 (0) | 2019.06.27 |