Zeller's congruence is an algorithm to calculate the day of the week. The formula is:
h=(q+⌊26(m+1)10⌋+k+⌊k4⌋+⌊j4⌋+5j)%7
where:
⌊…⌋ indicates floor division
h is the day of the week (0 - Saturday, 1 - Sunday, 2 - Monday, 3 - Tuesday, 4 - Wednesday, 5 - Thursday, 6 - Friday)
q is the day of the month
m is the month (3 - March, 4 - April, ... 12 - December). January and February are counted as months 13 and 14 of the previous year, e.g. for January 25 2013, you would use the 25th day of the 13th month in 2012.
j is the century, e.g. 20 for 2013
k is the year of the century, e.g. 13 for 2013.
Write a program using functions that prompts the user to enter a year (e.g. 2008), month (e.g. 1-12), and day of the month (e.g. 1-31), and then displays the name of the day of the week. For example, for year 2013, month 1, and day of month 25, the day of the week is Friday; the user inputs 2013, 1, and 25 in response to your prompts and then you calculate h which will be 6, and then output Friday. Run the program for five different dates. Testing must include different months including January and February, different centuries, and different years.
Now for this question i used 2 modules: 1 being the function module and 1 being my main program.
Function module:
h =(q+(26*m+1))/((10)+k+(k/4)+(j/4)+(5*j))%7
if h==1:
day="Sunday"
elif h==2:
day="Monday"
elif h==3:
day="Tuesday"
elif h==4:
day="Wednesday"
elif h==5:
day="Thursday"
elif h==6:
day="Friday"
else:
day="Saturday"
return day
Main program module:
import q5_function
q = int (input("enter day of the month"))
m = int (input ("enter the month"))
j = int (input("enter the century"))
k = int (input("enter the year of the century"))
h=q5_function.func_day(q, m, j, k)
print ("the day is {0}".format(h))
Now if i try and run this program it keeps printing "saturday" and nothing els.
How can i get the formula to work?