Answer to Question #178737 in Python for Woyengimiesindo Malati

Question #178737

Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is


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.

j is the century (i.e., ⌊year/100⌋).

k is the year of the century (i.e., year % 100).


Write a program that prompts the user to enter a year, month, and day of the month, and then it displays the name of the day of the week. Sample runs of program are given below:



1
Expert's answer
2021-04-07T00:18:38-0400
# Gregorian calendar program
day_weekly = {0: 'Saturday', 1: 'Sunday', 2: 'Monday', 3: 'Tuesday', 
              4: 'Wednesday', 5: 'Thursday', 6: 'Friday'}
monthеs = {'Jan': 13, 'Feb': 14, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, 
         'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}


def zeller_cong(arg):
    year, month , day = arg.split()
    year = int(year)
    j = year//100
    k = year % 100
    month = monthеs[month]
    day = int(day)
    res = (day +int(13*(month+1)/5)+ k +int(k/4)+int(j/4)-2*j)%7
    return day_weekly[res]


    
print ('Date format example 2019 Dec 4')
print(zeller_cong(input('Enter the date in the specified format: ')))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS