Answer to Question #263876 in Python for Kelly

Question #263876

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


where: h=(q+²⁶(m+I)/10 + k/4 + i/4 + 5i)%7



• 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)



Note that the division in the formula performs an integer division. Write a program that prompts the user to enter a year, month, and day of the month, and displays the name of the day of the


week. Here are some sample runs:



(Hint: January and February are counted as 13 and 14 in the formula, so you need to convert the user input 1 to 13 and 2 to 14 for the month and change the year to the previous year.)

1
Expert's answer
2021-11-11T00:07:51-0500
# Here is a Python3 program to find Find the Day
# function for a Date
 
def day_sw(h) :
    return {
        0 : "Saturday",
        1 : "Sunday",
        2 : "Monday",
        3 : "Tuesday",
        4 : "Wednesday",
        5 : "Thursday",
        6 : "Friday",
    }[h]


#function for entering month and day and year in a asked order
def Zellercongruence(day, month, year) :
    if (month == 1) :
        month = 13
        year = year - 1
 
    if (month == 2) :
        month = 14
        year = year - 1
    q = day
    m = month
    k = year % 100;
    i = year // 100;
    h = q + 13 * (m + 1) // 5 + k + k // 4 + i // 4 + 5 * i
    h = h % 7
    print(day_sw (h))
     
     
     
# Driver code
Zellercongruence(26, 10, 2020) 
#Zellercongruence(dd/mm/year) 
# This code is contributed by expert Suhrob Umarov

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