Advertisement
Guest User

Weekday

a guest
Dec 1st, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1. # Weekday, a script to calculate the day of the week
  2.  
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7.  
  8. print "Weekday will calculate the day of the week for you."
  9.  
  10. month = raw_input("Enter the month (the whole word): ")
  11. day = int(raw_input("Enter the day of the month: "))
  12. year = int(raw_input("Enter the year: "))
  13.  
  14. if year < 1500 or year > 2699:
  15.     print "Error: this program cannot find dates before 1500 or after 2699."
  16.    
  17.  
  18. if month in ("April", "July"):
  19.     month_code = 0
  20.    
  21. elif month in ("January", "October"):
  22.     month_code = 1
  23.    
  24. elif month in ("May"):
  25.     month_code = 2
  26.    
  27. elif month in ("August"):
  28.     month_code = 3
  29.    
  30. elif month in ("February", "March", "November"):
  31.     month_code = 4
  32.    
  33. elif month in ("June"):
  34.     month_code = 5
  35.    
  36. elif month in ("September", "December"):
  37.     month_code = 6
  38.  
  39. year_breaker = str(year)
  40.    
  41. if int(year_breaker[:2]) == 15 or int(year_breaker[:2]) == 19 or int(year_breaker[:2]) == 23:
  42.     century_code = 0
  43.  
  44. elif int(year_breaker[:2]) == 18 or int(year_breaker[:2]) == 22 or int(year_breaker[:2]) == 26:
  45.     century_code = 2
  46.    
  47. elif int(year_breaker[:2]) == 17 or int(year_breaker[:2]) == 21 or int(year_breaker[:2]) == 25:
  48.     century_code = 4
  49.    
  50. elif int(year_breaker[:2]) == 16 or int(year_breaker[:2]) == 20 or int(year_breaker[:2]) == 24:
  51.     century_code = 6
  52.    
  53.  
  54. if month in ("January", "February") and year % 4 == 0 and year % 100 != 0:
  55.     total = day + month_code + (int(year_breaker[-2:]) // 4) + int(year_breaker[-2:]) + century_code - 1
  56.  
  57. elif month in ("January", "February") and year % 400 == 0:
  58.     total = day + month_code + (int(year_breaker[-2:]) // 4) + int(year_breaker[-2:]) + century_code - 1
  59.  
  60. else:
  61.     total = day + month_code + (int(year_breaker[-2:]) // 4) + int(year_breaker[-2:]) + century_code
  62.  
  63.  
  64. if total % 7 == 0:
  65.     print "%s %s, %s was a Saturday." % (month, day, year)
  66.    
  67. elif total % 7 == 1:
  68.     print "%s %s, %s was a Sunday." % (month, day, year)
  69.  
  70. elif total % 7 == 2:
  71.     print "%s %s, %s was a Monday." % (month, day, year)
  72.    
  73. elif total % 7 == 3:
  74.     print "%s %s, %s was a Tuesday." % (month, day, year)
  75.    
  76. elif total % 7 == 4:
  77.     print "%s %s, %s was a Wednesday." % (month, day, year)
  78.  
  79. elif total % 7 == 5:
  80.     print "%s %s, %s was a Thursday." % (month, day, year)
  81.    
  82. elif total % 7 == 6 :
  83.     print "%s %s, %s was a Friday." % (month, day, year)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement