Advertisement
gnamp

yearsGivenDateFellOnParticularDayListerDM

Jun 14th, 2017
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. #Years Given Date Fell on Particular Day lister
  2. #for Python 2.x
  3. #by Dominic D. McGough
  4. #Wednesday, 14th June, 2017
  5.  
  6. def weekDay(year, month, day):
  7.     offset = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
  8.     week   = ['Sunday',
  9.               'Monday',
  10.               'Tuesday',
  11.               'Wednesday',
  12.               'Thursday',  
  13.               'Friday',
  14.               'Saturday']
  15.     afterFeb = 1
  16.     if month > 2: afterFeb = 0
  17.     aux = year - 1700 - afterFeb
  18.     # dayOfWeek for 1700/1/1 = 5, Friday
  19.     dayOfWeek  = 5
  20.     # partial sum of days between current date and 1700/1/1
  21.     dayOfWeek += (aux + afterFeb) * 365                  
  22.     # leap year correction    
  23.     dayOfWeek += aux / 4 - aux / 100 + (aux + 100) / 400    
  24.     # sum monthly and day offsets
  25.     dayOfWeek += offset[month - 1] + (day - 1)              
  26.     dayOfWeek %= 7
  27.     return week[dayOfWeek]
  28.  
  29. DayOfWeek = input("enter day of week [\"in quotes\" - eg. \"Monday\"]: ")
  30. DayOfMonth = input("enter day of month - [eg. 25]: ")
  31. Month = input("enter month - [eg. 12]: ")
  32.  
  33. import datetime
  34. now = datetime.datetime.now()
  35. thisYear = now.year
  36.  
  37. for year in range(1700, thisYear+7):
  38.     if weekDay(year, Month, DayOfMonth) == DayOfWeek:
  39.         print(year),
  40. print "[DONE]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement