Day Name - 2
Given the weekday of the first day of the month, determine the day of the week of the given date in that month.
The first line is a string
The output should be a string.
In the given example,
D = Monday. As the 1st of the day of the month is a Monday, it means the 7th and 14th of the month will also be Mondays (A week has 7 days). So the 16th day (N = 16) of the month will be a Tuesday.So, the output should be
Tuesday.
Sample Input 1
Monday
16
Output:
Tuesday
sample Input-2:
Tuesday
17
Output:
Thursday
def determine_day_by_number(start_day: str, month_day_number: int):
number_to_day = dict(
[[1, 'Monday'], [2, 'Tuesday'], [3, 'Wednesday'], [4, 'Thursday'], [5, 'Friday'], [6, 'Saturday'],
[7, 'Sunday']])
day_to_number = dict(zip(number_to_day.values(), number_to_day.keys()))
if start_day not in number_to_day.values():
print('Wrong day name')
exit()
start_day_number = day_to_number[start_day]
shift = get_day_shift(start_day_number, month_day_number)
number_of_required_day = start_day_number + shift
return number_to_day[number_of_required_day]
def get_day_shift(start_day_number: int, month_day_number: int):
shift = month_day_number
if start_day_number + shift > 7:
number_of_full_weeks = shift // 7
shift -= 7 * number_of_full_weeks + 1
return shift if not start_day_number + shift > 7 else shift - 7
def main():
start_day = input('Enter start day: ')
month_day_number = int(input('Enter shift number: '))
day = determine_day_by_number(start_day, month_day_number)
print(day)
if __name__ == '__main__':
main()
Comments
Leave a comment