본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 70

반응형

Q>

You prefer a good old 12-hour time format.

(좋은 12 시간 형식을 선호합니다.)

But the modern world we live in would rather use the 24-hour format and you see it everywhere.

(그러나 우리가 살고있는 현대 세계는 오히려 24 시간 형식을 사용하고 어디에서나 볼 수 있습니다.)

Your task is to convert the time from the 24-h format into 12-h format by following the next rules:
- the output format should be 'hh:mm a.m.' (for hours before midday) or 'hh:mm p.m.' (for hours after midday)
- if hours is less than 10 - don't write a '0' before it. For example: '9:05 a.m.'

당신의 임무는 다음 규칙을 따라 24 시간 형식에서 12 시간 형식으로 시간을 변환하는 것입니다 : - 출력 형식은 'hh : mm a.m'이어야합니다. (정오 이전에 몇 시간 동안) 또는 'hh : mm p.m.' (정오 이후 몇 시간 동안) - 시간이 10보다 작 으면 - 앞에 '0'을 쓰지 마십시오. 예 : '오전 9시 5 분')
Here you can find some useful information about the 12-hour format.

(여기에 12 시간 형식에 대한 유용한 정보가 있습니다.)

 

Input: Time in a 24-hour format (as a string).

         (24 시간 형식의 시간 (문자열).)

 

Output: Time in a 12-hour format (as a string).

           (12 시간 형식의 시간 (문자열).)

 

Example:

time_converter('12:30') == '12:30 p.m.'
time_converter('09:00') == '9:00 a.m.'
time_converter('23:15') == '11:15 p.m.'

 

How it is used: For work with the different time formats.

                     (서로 다른 시간 형식의 작업.)

 

Precondition: '00:00' <= time <= '23:59'

 

A>

def time_converter(time):
    h, m = map(int, time.split(':'))
    return f"{(h-1)%12+1}:{m:02d} {'ap'[h>11]}.m."

if __name__ == '__main__':
    print("Example:")
    print(time_converter('12:30'))

    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert time_converter('12:30') == '12:30 p.m.'
    assert time_converter('09:00') == '9:00 a.m.'
    assert time_converter('23:15') == '11:15 p.m.'
    print("Coding complete? Click 'Check' to earn cool rewards!")

 

O>

Example:
12:30 p.m.
Coding complete? Click 'Check' to earn cool rewards!

 

S>

https://py.checkio.org

반응형

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

Python Learn the basics Quiz 72  (0) 2019.06.19
Python Learn the basics Quiz 71  (0) 2019.06.17
Python Learn the basics Quiz 69  (0) 2019.06.15
Python Learn the basics Quiz 68  (0) 2019.06.15
Python Learn the basics Quiz 67  (0) 2019.06.14