Compose a program dayOfWeek that accepts a date as input and writes the day of t
ID: 3885554 • Letter: C
Question
Compose a program dayOfWeek that accepts a date as input and writes the day of the week on which that date falls. Your program should ask the user for three values: m (month), d (day), and y (year). For m use 1 for January, 2 for February, and so forth. For output write 0 for Sunday, 1 for Monday, 2 for Tuesday, and so forth. Use the following formulas, for the Gregorian calendar: y0 = y - (14 - m)/12 x = y0 + y0/4 - y0/100 + y0/400 m0 = m + 12*((14 - m)/12)- 2 d0 = (d + x + (31*m0)/12) % 7 Please note that all the divisions in the formulas above are integer divisions. They represent the quotient part of the division between the two operands. For example, on what day of the week was August 2, 1953? y = 1953 - 0 = 1953 x = 1953 + 1953/4 - 1953/100 + 1953/400 -= 2426 m = 8 + 12*0 - 2 = 6 d = (2 + 2426 + (31*6)/12) % 7 = 2443 % 7 = 0 (Sunday) Here's an example of a possible sample run: Please enter the month: 8 Please enter the day: 2 Please enter the year: 1953 The day of the week for the given date is: 0Explanation / Answer
m = int(input("Please enter the month: "))
d = int(input("Please enter the day: "))
y = int(input("Please enter the year: "))
y = y - int((14-m)/12)
x = y + int(y/4) - int(y/100) + int(y/400)
m = m + 12 * int((14-m)/12) - 2
d =(d + x + int((31 * m)/12)) % 7
print("The day of the week for the given date is:",d)
Output:
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.