Answer to Question #259708 in Python for Sai

Question #259708

Day Name-2

1
Expert's answer
2021-11-03T04:22:38-0400
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(

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog