#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목birthday 함수2022-04-01 16:09
작성자

def days_difference(day1, day2):

    """ (int, int) -> int


    Return the number of days between day1 and day2,

    which are both in the range 1-365

    (thus indicating the day of the year).


    >>> days_difference(200, 224)

    24

    >>> days_difference(50, 50)

    0

    >>> days_difference(100, 99)

    -1

    """


    return day2 - day1

    day_ahead = days_difference(day1, day2)



def get_weekday(current_weekday, day_ahead):

    """ (int, int) -> int


    Return which day of the week it will be day_ahead days from current_weekday.

    current_weekday is the current day of the week and is in the range 1-7,

    indicating whether today is Sunday (1), Monday (2), ...,  Saturday (7).

   day_ahead is the number of days after today.


    >>> get_weekday(3,2)

    5

    >>> get_weekday(6,1)

    7

    >>>get_weekday(7,1)

    1

    """

  

    return(current_weekday + day_ahead -1) % 7 +1



def get_birthday_weekday(current_weekday, current_day, birthday_day):

    """ (int, int, int) -> int


    Return the day of the week it will be on birthday_day,

    given that the day of the week is current_weekday and the day of the year is current_day


    current_weekday is the current day of the week and is in the range 1-7,

    indicating whether today is Sunday (1), Monday (2), ...,  Saturday (7).

    current_day and birthday_day are both in the range 1-365.


    >>> get_birthday_weekday(6,3,4)

    7

    >>> get_birthday_weekday(6,3,116) % Day116 ->  Apr25

    7

    >>> get_birthday_weekday(7, 116, 3)

    6

    """


    days_diff  = days_difference(current_day, birthday_day)

    return get_weekday(current_weekday, days_diff)


------------------------------------------------------------------------------------------------------------------

수업 내용 토대로 작성한 코드인데

계속 NameError: name 'day_ahead' is not defined 이게 뜨네요. 두번째 함수부분에서 잘못된 것 같은데 어떻게 수정해야할지 모르겠습니다.


댓글