Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def zeller():
- #accept year from user, transform it to an integer
- year = int(input("\nEnter year (e.g., 2008): "))
- #print error if year is 1752 0r less
- if (year < 1753):
- print("Year must be > 1752. Illegal year entered:", year, "\n")
- return
- #accept month, transform to an integer
- month = int( input("\nEnter month (1-12): "))
- #print error if month is invalid
- if (month < 1) or (month > 12):
- print("Month must be in [1..12]. Illegal month entered:", month, "\n")
- return
- #accept date, transform to integer
- d = int(input("\nEnter day of the month (1-31): "))
- #print error if month is invalid
- if (d < 1) or (d > 31):
- print("Day must be in [1..31]. Illegal day entered:", d, "\n")
- return
- #Adjust for january and february
- print("before")
- if (month == 1):
- m = 13
- elif (month == 2):
- m = 14
- else:
- m = month
- return
- print("after")
- #Adjust year in case of january and february
- Y = 0
- if (m == 13) or (m == 14):
- Y = year - 1
- else:
- Y = year
- return
- print(Y)
- #Compute K
- K = Y % 100
- #Compute J
- J = Y - K
- #Compute h
- h = (d + (13 * (m + 1))//5 + K + K//4 + J//4 + 5*J ) % 7
- #Convert h to days
- if (h == 0):
- day = "Saturday"
- elif (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"
- return
- #Print result
- print("Day of the week is", day)
- zeller()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement