Problem 1: Find the day of the week corresponding to a date

Write a Python program that reads from standard input a date (given with Month, Day, and Year) and compute the corresponding day of the week.

Let us suppose that we have read the date as MONTH, DAY, and YEAR. The calculation of the day of the week is based on the Zeller's congruence formula:

h = ( q + (13*(m+1))/5 + K + K/4 + J/4 + 5*J) (modulo 7)

where:

  • J is the number of the century: J = YEAR/ 100
  • K is the year within the century, with a correction: K= YEAR%100 + C, with C=0 if MONTH>2 (i.e. starting from March) and C=-1 if MONTH = 1 or 2 (January or February)
  • m is a modified month index: m = MONTH if MONTH >2, and m = MONTH+12 if MONTH = 1 or 2
  • q is the day of the month: q = DAY
  • h is the day of the week [where 1 is Sunday]. The modulo in the equation means that we take the remainder of the division by 7 (%7 in Python).

Find number of days between two dates

Write a Python program that reads from standard input two dates (both given with Month, Day, and Year) and compute the corresponding number of days that have elapsed between these two dates.

Let us suppose that we have read the first date as MONTH1, DAY1, and YEAR1. We convert this date into a universal date, the Julian Day Number (JDN) using the formula:

JDN1 = DAY1 + (153*m1+2)/5 + 365*y1 + y1/4 - y1/100 + y1/400 - 32045

where:

  • a1 = (14-MONTH1)/12
  • y1 = YEAR1 + 4800 - a1
  • m1 = MONTH1 + 12*a1 - 3
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.