Advertisement
Guest User

zellercode

a guest
Feb 10th, 2025
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. def zeller():
  2.  
  3. #accept year from user, transform it to an integer
  4. year = int(input("\nEnter year (e.g., 2008): "))
  5. #print error if year is 1752 0r less
  6. if (year < 1753):
  7. print("Year must be > 1752. Illegal year entered:", year, "\n")
  8. return
  9. #accept month, transform to an integer
  10. month = int( input("\nEnter month (1-12): "))
  11. #print error if month is invalid
  12. if (month < 1) or (month > 12):
  13. print("Month must be in [1..12]. Illegal month entered:", month, "\n")
  14. return
  15. #accept date, transform to integer
  16. d = int(input("\nEnter day of the month (1-31): "))
  17. #print error if month is invalid
  18. if (d < 1) or (d > 31):
  19. print("Day must be in [1..31]. Illegal day entered:", d, "\n")
  20. return
  21.  
  22. #Adjust for january and february
  23. print("before")
  24. if (month == 1):
  25. m = 13
  26. elif (month == 2):
  27. m = 14
  28. else:
  29. m = month
  30. return
  31.  
  32. print("after")
  33. #Adjust year in case of january and february
  34. Y = 0
  35. if (m == 13) or (m == 14):
  36. Y = year - 1
  37. else:
  38. Y = year
  39. return
  40. print(Y)
  41. #Compute K
  42. K = Y % 100
  43. #Compute J
  44. J = Y - K
  45.  
  46.  
  47. #Compute h
  48. h = (d + (13 * (m + 1))//5 + K + K//4 + J//4 + 5*J ) % 7
  49.  
  50. #Convert h to days
  51. if (h == 0):
  52. day = "Saturday"
  53. elif (h == 1):
  54. day = "Sunday"
  55. elif (h == 2):
  56. day = "Monday"
  57. elif (h == 3):
  58. day = "Tuesday"
  59. elif (h == 4):
  60. day = "Wednesday"
  61. elif (h == 5):
  62. day = "Thursday"
  63. elif (h == 6):
  64. day = "Friday"
  65. return
  66.  
  67. #Print result
  68. print("Day of the week is", day)
  69.  
  70. zeller()
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement