Write a function named find_day which accepts two arguments, an integer month (1-12), and an integer day of month (1-31). find_day should return an integer (1-7) indicating the day of the week for the year 2019. find. A return value of 1 represents Sunday, 2 represents Monday, 3 represents Tuesday, and so forth. 7 will represent Saturday. For example, find_day(1, 5) should return 7 because January 5, 2019 was a Saturday.

Respuesta :

Answer:

In Python:

import datetime

def find_day(month,day):

    days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']

    ans = datetime.date(2019, month, day)

    ans = ans.strftime("%A")

    print(days.index(ans)+1)

Explanation:

This imports datetime module

import datetime

The function is defined here

def find_day(month,day):

This initializes the days of the week as a list

    days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']

This gets the day of the week using the datetime module as a date

    ans = datetime.date(2019, month, day)

This converts the date as string its respective day of the week

    ans = ans.strftime("%A")

This prints the day of the week base on its position in the above defined list

    print(days.index(ans)+1)

ACCESS MORE