Question: PYTHON I need some basic python homework help! Write a program that prompts the user to enter a date (day, month, and year). Your program
PYTHON
I need some basic python homework help!
Write a program that prompts the user to enter a date (day, month, and year). Your program will print out the day of the week for that date.
You do not need to validate the input. That means you can assume:
- the year will be entered as a four-digit number in the range 1900 through 2100 inclusive.
- the month will be one of the strings "January", "February", . . ., "December".
- the day will be an integer between 1 and 31 inclusive.
- the user will not enter a date that doesn't exist (such as November 31, or February 29 in a non-leap year).
Algorithm:
This algorithm is called "Zeller's Congruence" after the person who developed it, Rev. Christian Zeller.
- Let "a" be an integer based on the month of the year. For the months January through December, set a = 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10 (in that order).
- Let "b" be the day of the month, exactly as entered by the user.
- Let "c" be the last two digits of the year; for instance, if the year is 2018, c should equal 18. Important exception: if the month is January or February, subtract one from the year first. (In order to handle leap years correctly, the algorithm treats January and February as though they are the last two months of the previous year. That's why you do the assignments for "a" in that funny way.)
- Let "d" be the first two digits of the year. (Make sure you calculate this AFTER you subtract one if you had to make any adjustments for January or February.)
Some sample calculations: for July 31, 1929, you should get a = 5, b = 31, c = 29, and d = 19. Similarly, for January 3, 1988, you should get a = 11, b = 3, c = 87, and d = 19.
Then calculate the following quantities:
w = (13 * a - 1 ) // 5 x = c // 4 y = d // 4 z = w + x + y + b + c - 2 * d r = z % 7 r = (r + 7) % 7 [to take care of negative values of r]
If you did this correctly, r gives you the day of the week. r = 0 represents Sunday, r = 1 represents Monday, and so on.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
