Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Years Given Date Fell on Particular Day lister
- #for Python 2.x
- #by Dominic D. McGough
- #Wednesday, 14th June, 2017
- def weekDay(year, month, day):
- offset = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
- week = ['Sunday',
- 'Monday',
- 'Tuesday',
- 'Wednesday',
- 'Thursday',
- 'Friday',
- 'Saturday']
- afterFeb = 1
- if month > 2: afterFeb = 0
- aux = year - 1700 - afterFeb
- # dayOfWeek for 1700/1/1 = 5, Friday
- dayOfWeek = 5
- # partial sum of days between current date and 1700/1/1
- dayOfWeek += (aux + afterFeb) * 365
- # leap year correction
- dayOfWeek += aux / 4 - aux / 100 + (aux + 100) / 400
- # sum monthly and day offsets
- dayOfWeek += offset[month - 1] + (day - 1)
- dayOfWeek %= 7
- return week[dayOfWeek]
- DayOfWeek = input("enter day of week [\"in quotes\" - eg. \"Monday\"]: ")
- DayOfMonth = input("enter day of month - [eg. 25]: ")
- Month = input("enter month - [eg. 12]: ")
- import datetime
- now = datetime.datetime.now()
- thisYear = now.year
- for year in range(1700, thisYear+7):
- if weekDay(year, Month, DayOfMonth) == DayOfWeek:
- print(year),
- print "[DONE]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement