본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 77

반응형

Q>

How old are you in number of days?

(며칠 째 몇 살입니까?)

It's easy to calculate - just subtract your birthday from today.

(계산하기 쉽습니다 - 오늘부터 생일을 빼십시오.)

We could make this a real challenge though and count the difference between any dates.

(우리는 이것을 진정한 도전으로 만들 수 있으며 어떤 날짜의 차이라도 세어 볼 수 있습니다.)

You are given two dates as tuples with three numbers - year, month and day.

(년, 월, 일 세 개의 숫자가있는 튜플로 두 개의 날짜가 부여됩니다.)

For example: 19 April 1982 will be (1982, 4, 19).

(예 : 1982 년 4 월 19 일 (1982, 4, 19).)

You should find the difference in days between the given dates.

(주어진 날짜 사이의 날짜 차이를 찾아야합니다.)

For example between today and tomorrow = 1 day.

(예를 들어 오늘과 내일 사이 = 1 일.)

The difference will always be either a positive number or zero, so don't forget about absolute value.

(차이는 항상 양수 또는 0이 될 것이므로 절대 값을 잊지 마십시오.)

 

Input: Two dates as tuples of integers.

         (두 개의 날짜가 정수의 튜플입니다.)

 

Output: The difference between the dates in days as an integer.

           (정수로 나타낸 날짜 간의 차이입니다.)

 

Example:

days_diff((1982, 4, 19), (1982, 4, 22)) == 3
days_diff((2014, 1, 1), (2014, 8, 27)) == 238
days_diff((2014, 8, 27), (2014, 1, 1)) == 238

 

How it is used: Python has batteries included, so in this mission you will need to learn how to use completed modules so that you don't have to invent the bicycle all over again.

                     (파이썬에는 배터리가 포함되어 있으므로이 임무에서는 완성 된 모듈을 사용하여 자전거를 다시 만들 필요가없는 방법을 배워야합니다.)

 

Precondition: Dates between 1 january 1 and 31 december 9999. Dates are correct.

                   (1 월 1 일부터 9 월 9 일까지의 날짜. 날짜가 정확합니다)

 

A>

from datetime import datetime

def days_diff(date1, date2):
    """
        Find absolute diff in days between dates
    """
    return abs((datetime(*date1) - datetime(*date2)).days)

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert days_diff((1982, 4, 19), (1982, 4, 22)) == 3
    assert days_diff((2014, 1, 1), (2014, 8, 27)) == 238
    assert days_diff((2014, 8, 27), (2014, 1, 1)) == 238

 

O>

 

S>

https://py.checkio.org

반응형

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

Python Learn the basics Quiz 79  (0) 2019.06.20
Python Learn the basics Quiz 78  (0) 2019.06.20
Python Learn the basics Quiz 76  (0) 2019.06.20
Python Learn the basics Quiz 75  (0) 2019.06.20
Python Learn the basics Quiz 74  (0) 2019.06.20