# A python script to calculate the number of days # since your date of birth. # Solved it as a assignment problem from the Udacity course site # Though the solution is a lot different from theirs def isleap(year): if year%400==0: return True elif year%100==0: #got from wikipedia...the code for leap year return False elif year%4==0: return True else: return False def daysleft(year,month,day): if isleap(year): daysOfMonths = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] else: daysOfMonths = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] x=daysOfMonths[month-1]-day for i in range(month,12): x=x+daysOfMonths[i] return x def daysbefore(year,month,day): if isleap(year): return 366-daysleft(year,month,day) else: return 365-daysleft(year,month,day) def daysBetweenDates(year1, month1, day1, year2, month2, day2): if year1==year2: return abs(daysleft(year1,month1,day1)-daysleft(year2,month2,day2)) else: first=daysleft(year1,month1,day1) last=daysbefore(year2,month2,day2) middle=0 while year1+1