Answer to Question #221291 in Python for Dr Kiran Tummalapa

Question #221291

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.


Input

The first line is a string D.

The second line is an integer N.

Output

The output should be a string.


Explanation

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 be Sundays (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


Sample Output 1


Tuesday


1
Expert's answer
2021-07-31T07:44:33-0400
def determineDayByNumber(startDay: str, monthDayNumber: int):
    numberToDay = dict(
        [[1, "Monday"], [2, "Tuesday"], [3, "Wednesday"], [4, "Thursday"], [5, "Friday"], [6, "Saturday"],
         [7, "Sunday"]])
    dayToNumber = dict(zip(numberToDay.values(), numberToDay.keys()))


    if startDay not in numberToDay.values():
        print("Invalid Day Name")
        exit()


    startDayNumber = dayToNumber[startDay]
    shiftDays = getDayShift(startDayNumber, monthDayNumber)
    numberOfRequiredDay = startDayNumber + shiftDays


    return numberToDay[numberOfRequiredDay]




def getDayShift(start_day: int, month_day: int):
    shifter = month_day
    if start_day + shifter > 7:
        number_of_weeks = shifter // 7
        shifter -= 7 * number_of_weeks + 1
    return shifter if not start_day + shifter > 7 else shifter - 7




print("Sample Input 1")
print("Monday")
print("16")
print("Sample Output 1")
startDay = "Monday"
monthDayNumber = 16


dayOfWeek = determineDayByNumber(startDay, monthDayNumber)
print(dayOfWeek)



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
APPROVED BY CLIENTS