Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Weekday, a script to calculate the day of the week
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- print "Weekday will calculate the day of the week for you."
- month = raw_input("Enter the month (the whole word): ")
- day = int(raw_input("Enter the day of the month: "))
- year = int(raw_input("Enter the year: "))
- if year < 1500 or year > 2699:
- print "Error: this program cannot find dates before 1500 or after 2699."
- if month in ("April", "July"):
- month_code = 0
- elif month in ("January", "October"):
- month_code = 1
- elif month in ("May"):
- month_code = 2
- elif month in ("August"):
- month_code = 3
- elif month in ("February", "March", "November"):
- month_code = 4
- elif month in ("June"):
- month_code = 5
- elif month in ("September", "December"):
- month_code = 6
- year_breaker = str(year)
- if int(year_breaker[:2]) == 15 or int(year_breaker[:2]) == 19 or int(year_breaker[:2]) == 23:
- century_code = 0
- elif int(year_breaker[:2]) == 18 or int(year_breaker[:2]) == 22 or int(year_breaker[:2]) == 26:
- century_code = 2
- elif int(year_breaker[:2]) == 17 or int(year_breaker[:2]) == 21 or int(year_breaker[:2]) == 25:
- century_code = 4
- elif int(year_breaker[:2]) == 16 or int(year_breaker[:2]) == 20 or int(year_breaker[:2]) == 24:
- century_code = 6
- if month in ("January", "February") and year % 4 == 0 and year % 100 != 0:
- total = day + month_code + (int(year_breaker[-2:]) // 4) + int(year_breaker[-2:]) + century_code - 1
- elif month in ("January", "February") and year % 400 == 0:
- total = day + month_code + (int(year_breaker[-2:]) // 4) + int(year_breaker[-2:]) + century_code - 1
- else:
- total = day + month_code + (int(year_breaker[-2:]) // 4) + int(year_breaker[-2:]) + century_code
- if total % 7 == 0:
- print "%s %s, %s was a Saturday." % (month, day, year)
- elif total % 7 == 1:
- print "%s %s, %s was a Sunday." % (month, day, year)
- elif total % 7 == 2:
- print "%s %s, %s was a Monday." % (month, day, year)
- elif total % 7 == 3:
- print "%s %s, %s was a Tuesday." % (month, day, year)
- elif total % 7 == 4:
- print "%s %s, %s was a Wednesday." % (month, day, year)
- elif total % 7 == 5:
- print "%s %s, %s was a Thursday." % (month, day, year)
- elif total % 7 == 6 :
- print "%s %s, %s was a Friday." % (month, day, year)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement