Advertisement
Guest User

Untitled

a guest
Jun 28th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. # By Websten from forums
  2. #
  3. # Given your birthday and the current date, calculate your age in days.
  4. # Account for leap days.
  5. #
  6. # Assume that the birthday and current date are correct dates (and no
  7. # time travel).
  8. #
  9.  
  10. def daysBetweenDates(year1, month1, day1, year2, month2, day2):
  11.     yeardic = {"1True":31, "2True":29, "3True":31, "4True":30, "5True":31, "6True":30, "7True":31, "8True":31, "9True":30, "10True":31, "11True":30, "12True":31,"1False":31, "2False":28, "3False":31, "4False":30, "5False":31, "6False":30, "7False":31, "8False":31, "9False":30, "10False":31, "11False":30, "12False":31}
  12.     totaldays = 0
  13.     def isleapyear():
  14.         if year1 % 400 == 0:
  15.             return str(month1) + "True"
  16.         elif year1 % 100 == 0:
  17.             return str(month1) + "False"
  18.         elif year1 % 4 == 0:
  19.             return str(month1) + "True"
  20.         else:
  21.             return str(month1) + "False"
  22.     totaldays += yeardic[str(isleapyear())] -day1
  23.     month1 +=1
  24.     if month1 == 13:
  25.         month1 == 1
  26.         year1 += 1
  27.     while (month1,year1) != (month2,year2):
  28.         totaldays += yeardic[str(isleapyear())]
  29.         month1 +=1
  30.         if month1 == 13:
  31.             month1 = 1
  32.             year1+=1
  33.     totaldays += day2
  34.     print totaldays
  35.     return totaldays
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement