Advertisement
Guest User

Zeller's Algorithm

a guest
Jun 24th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.96 KB | None | 0 0
  1. months = {"1":11, "2":12, "3":1, "4":2, "5":3, "6":4,
  2. "7":5, "8":6, "9":7, "10":8, "11":9, "12":10}
  3. days = {"1":"Monday", "2":"Tuesday","3":"Wednesday","4":"Thursday","5":"Friday","6":"Saturday","0":"Sunday"}
  4. bMonth = "0"
  5. bDay = "0"
  6. bYear = "0"
  7. bCent = "0"
  8. today = datetime.now()
  9. born = "You were born on a "
  10.  
  11.  
  12. validInput = False
  13. while (validInput == False):
  14.     while(len(bYear)!=2):
  15.         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 ")
  16.     try:
  17.         bYear = int(bYear)
  18.         if bYear >= 0 and bYear <= 99:
  19.             validInput = True
  20.         else:
  21.             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 ")
  22.     except ValueError:
  23.       bYear = input("You made an invalid entry. \nEnter the two digit year: \n(e.g. if you were born in 1980 enter 80) YY ")
  24.  
  25. validInput = False
  26. while (validInput == False):
  27.     while(len(bCent)!=2):
  28.         bCent = input("Enter the two digit century: \n(e.g. if you were born in 1980 enter 19) CC ")
  29.  
  30.     try:
  31.         bCent = int(bCent)
  32.         if bCent >= 0 and bCent <= 99:
  33.             validInput = True
  34.         else:
  35.             bCent= input("Enter the two digit century: \n(e.g. if you were born in 1980 enter 19) CC ")
  36.     except ValueError:
  37.       bCent = input("You made an invalid entry. \nEnter the two digit century: \n(e.g. if you were born in 1980 enter 19) CC ")
  38.  
  39. validInput = False
  40. while (validInput == False):
  41.     while(len(bMonth)!=2):
  42.         bMonth = input("Enter a number for the month: MM ")
  43.  
  44.     try:
  45.         bMonth = int(bMonth)
  46.         if bMonth >= 1 and bMonth <= 12:
  47.             validInput = True
  48.         else:
  49.             bMonth = input("Enter a number for the month: MM ")
  50.     except ValueError:
  51.       bMonth = input("You made an invalid entry. \nEnter a number for the month: MM ")
  52.  
  53. validInput = False
  54. while (validInput == False):
  55.     while(len(bDay)!=2):
  56.         bDay = input("Enter a number for the day: DD ")
  57.  
  58.     try:
  59.         bDay = int(bDay)
  60.         if 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 == 9:
  68.             if bDay >= 1 or bDay <=30:
  69.                 validInput = True
  70.         elif bMonth == 4:
  71.             if bDay >= 1 or bDay <=30:
  72.                 validInput = True
  73.         elif bMonth == 6:
  74.             if bDay >= 1 or bDay <=30:
  75.                 validInput = True
  76.         elif bMonth == 11:
  77.             if bDay >= 1 or bDay <=30:
  78.                 validInput = True
  79.         elif bMonth == 1:
  80.             if bDay >= 1 or bDay <=31:
  81.                 validInput = True
  82.         elif bMonth == 3:
  83.             if bDay >= 1 or bDay <=31:
  84.                 validInput = True
  85.         elif bMonth == 5:
  86.             if bDay >= 1 or bDay <=31:
  87.                 validInput = True
  88.         elif bMonth == 7:
  89.             if bDay >= 1 or bDay <=31:
  90.                 validInput = True
  91.         elif bMonth == 8:
  92.             if bDay >= 1 or bDay <=31:
  93.                 validInput = True
  94.         elif bMonth == 10:
  95.             if bDay >= 1 or bDay <=31:
  96.                 validInput = True
  97.         else:
  98.             bDay= input("Enter a number for the day: DD ")
  99.     except ValueError:
  100.       bDay = input("You made an invalid entry. \nEnter a number for the day: DD ")
  101.  
  102. if today.year < int(str(bCent)+str(bYear)):
  103.     born = "You will born on a "
  104. A = int(months[str(bMonth)])
  105. B = int(bDay)
  106. if A == 11 or A == 12:
  107.     if bYear == 00:
  108.         bYear = 99
  109.         bCent = bCent - 1
  110.     else:
  111.         bYear = bYear - 1
  112. C = bYear
  113. D = bCent
  114.  
  115. W = int((13*A - 1) / 5)
  116. X = int(C / 4)
  117. Y = int(D / 4)
  118. Z = int(W + X + Y + B + C - 2*D)
  119. R = int((Z%7))
  120.  
  121. if (R < 0):
  122.     R = (R+7)%6
  123.  
  124. print (born + days[str(R)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement