Want more features on Pastebin? Sign Up, it's FREE!
Guest

Zeller's Algorithm (Python)

By: a guest on Jun 24th, 2013  |  syntax: Python  |  size: 3.68 KB  |  views: 278  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python
  2. from datetime import datetime
  3.  
  4. months = {"1":11, "2":12, "3":1, "4":2, "5":3, "6":4,
  5. "7":5, "8":6, "9":7, "10":8, "11":9, "12":10}
  6. days = {"1":"Monday", "2":"Tuesday","3":"Wednesday","4":"Thursday","5":"Friday","6":"Saturday","0":"Sunday"}
  7. bMonth = "0"
  8. bDay = "0"
  9. bYear = "0"
  10. bCent = "0"
  11. today = datetime.now()
  12. born = "You were born on a "
  13.  
  14.  
  15. validInput = False
  16. while (validInput == False):
  17.     while(len(bYear)!=2):
  18.         bYear = input("Want to know the day of the week you were born?\n Enter the two digit year: \n(e.g. if you were born in 1980 enter 80) YY ")
  19.     try:
  20.         bYear = int(bYear)
  21.         if bYear >= 0 and bYear <= 99:
  22.             validInput = True
  23.     except ValueError:
  24.       bYear = input("You made an invalid entry. \nEnter the two digit year: \n(e.g. if you were born in 1980 enter 80) YY ")
  25.  
  26. validInput = False
  27. while (validInput == False):
  28.     while(len(bCent)!=2):
  29.         bCent = input("Enter the two digit century: \n(e.g. if you were born in 1980 enter 19) CC ")
  30.  
  31.     try:
  32.         bCent = int(bCent)
  33.         if bCent >= 0 and bCent <= 99:
  34.             validInput = True
  35.     except ValueError:
  36.       bCent = input("You made an invalid entry. \nEnter the two digit century: \n(e.g. if you were born in 1980 enter 19) CC ")
  37.  
  38. validInput = False
  39. while (validInput == False):
  40.     while(len(bMonth)!=2):
  41.         bMonth = input("Enter a number for the month: MM ")
  42.  
  43.     try:
  44.         bMonth = int(bMonth)
  45.         if bMonth >= 1 and bMonth <= 12:
  46.             validInput = True
  47.     except ValueError:
  48.       bMonth = input("You made an invalid entry. \nEnter a number for the month: MM ")
  49.  
  50. validInput = False
  51. while (validInput == False):
  52.     while(len(bDay)!=2):
  53.         bDay = input("Enter a number for the day: DD ")
  54.  
  55.     try:
  56.         bDay = int(bDay)
  57.         if bMonth == 1:
  58.             if bDay >= 1 or bDay <=31:
  59.                 validInput = True
  60.         elif bMonth == 2:
  61.             if bYear%4 == 0:
  62.                 if bDay >=1 or bDay <= 29:
  63.                     validInput = True
  64.             else:
  65.                 if bDay >=1 or bDay <= 28:
  66.                     validInput = True
  67.         elif bMonth == 3:
  68.             if bDay >= 1 or bDay <=31:
  69.                 validInput = True
  70.         elif bMonth == 4:
  71.             if bDay >= 1 or bDay <=30:
  72.                 validInput = True
  73.         elif bMonth == 5:
  74.             if bDay >= 1 or bDay <=31:
  75.                 validInput = True
  76.         elif bMonth == 6:
  77.             if bDay >= 1 or bDay <=30:
  78.                 validInput = True
  79.         elif bMonth == 7:
  80.             if bDay >= 1 or bDay <=31:
  81.                 validInput = True
  82.         elif bMonth == 8:
  83.             if bDay >= 1 or bDay <=31:
  84.                 validInput = True
  85.         elif bMonth == 9:
  86.             if bDay >= 1 or bDay <=30:
  87.                 validInput = True
  88.         elif bMonth == 10:
  89.             if bDay >= 1 or bDay <=31:
  90.                 validInput = True
  91.         elif bMonth == 11:
  92.             if bDay >= 1 or bDay <=30:
  93.                 validInput = True
  94.         elif bMonth == 12:
  95.             if bDay >= 1 or bDay <=31:
  96.                 validInput = True
  97.     except ValueError:
  98.       bDay = input("You made an invalid entry. \nEnter a number for the day: DD ")
  99.  
  100. if today.year < int(str(bCent)+str(bYear)):
  101.     born = "You will born on a "
  102. A = int(months[str(bMonth)])
  103. B = int(bDay)
  104. if A == 11 or A == 12:
  105.     if bYear == 00:
  106.         bYear = 99
  107.         bCent = bCent - 1
  108.     else:
  109.         bYear = bYear - 1
  110. C = bYear
  111. D = bCent
  112.  
  113. W = int((13*A - 1) / 5)
  114. X = int(C / 4)
  115. Y = int(D / 4)
  116. Z = int(W + X + Y + B + C - 2*D)
  117. R = int((Z%7))
  118.  
  119. if (R < 0):
  120.     R = (R+7)%6
  121.  
  122. print (born + days[str(R)])
clone this paste RAW Paste Data