Question: please write in python 4. Dictionaries and day of the week. The following algorithm calculates the day of the week for a given date. It


please write in python
4. Dictionaries and day of the week. The following algorithm calculates the day of the week for a given date. It takes four integer variables with the following values: 2 zcentury the century, e.g. 20 for 2017 zyear year of the century, e.g. 17 for 2017 zmonth the month of the year, but March having the value 1, April the value 2, ..., December the value 10. To deal with the leap year problem January and February are treated differently. January has a value 11 and February a value of 12, but they are assigned to the previous year. The value of zyear should be set to year-1 when dealing with January and February. zday the day of the month (1, 2, 3,...31) The calculations are using integer arithmetic: w = (13*zmonth -1) //5 x = zyear 1/4 y = zcentury 1/4 z = W + x + y + zday + zyear 2*zcentury Calculate r the remainder of z divided by 7. r is the day of the week with 0 being Sunday, 1 Monday,..., 6 Saturday. r can be negative, in which case 7 should be added until one gets a non-negative day number. (a) Write a program which reads in dates in the DD-MM-YYYY format in the main program. Write a function weekday, which takes three integers with values of day, month and year as input and returns the weekday as Sunday, Monday, Tuesday, ..., Saturday. Use a dictionary for this step. Print the result in the main program. (b) Modify the code to also print out the date of the next Sunday after the input date: "The next Sunday following the input date is on DD-MM-YYYY." (c) Modify the code to also print out the next time after the input date when the same date of the month will again fall on the same weekday: "The next time MM DD) will fall onto a (e.g., Wednesday) will be in year (YYYY]." (d) Modify the code to find out how often Feb 29 will fall onto a Monday in the twenty-first century
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
