A year’s Doomsday is given by the equation: Doomsday = (((yr // 12) + (yr % 12)
ID: 3751409 • Letter: A
Question
A year’s Doomsday is given by the equation: Doomsday = (((yr // 12) + (yr % 12) + (yr % 12) // 4) % 7 + anchor) % 7 (1) where yr is the last two digits of the year and the anchor day is an integer between 0 and 7 with 0 corresponding to Sunday and 7 to Saturday. Write a program to calculate a year’s Doomsday. Prompt a user for the last two digits of the year and for the anchor day as an integer. Print out the Doomsday. Include the following:
• A function calc doom() that calculates the doomsday that takes two parameters yr and anchor and returns the doomsday
• A docstring in the function (i.e., right under the “def” line of the function surrounded by three single or double quotes) that explains the purpose of the function 2 Anchor days for 2000-2099 are Tuesday (=2) and for 1900-1999 Wednesday (=3). Example results are shown below.
1 Enter the last two digits of the year: 05
2 Enter the anchor day as an integer [0=Sunday, 7=Saturday]: 2
3
4 Doomsday = 1
5
6 Enter the last two digits of the year: 18
7 Enter the anchor day as an integer [0=Sunday, 7=Saturday]: 2 8 9 Doomsday = 3
Explanation / Answer
# function to calculate doomsday def calc_doom(yr,anchor): """ Function to find the doomsday of the year """ # The formula to calculate doomsday dday = (((yr/12) + (yr % 12) + (yr % 12)/ 4) % 7 + anchor) % 7; print "Doomsday = ", dday; #function to take user input def fun_dooms(): year = input(" Enter the last two digits of the year:") anchor= input("Enter the anchor day as an integer [0=Sunday, 7=Saturday]:") calc_doom(year,anchor); fun_dooms();
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.