Day Name-2
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