Skip to content

Instantly share code, notes, and snippets.

@mafriend
Last active December 11, 2015 18:26
Show Gist options
  • Save mafriend/3c450b075d315ac7e9b9 to your computer and use it in GitHub Desktop.
Save mafriend/3c450b075d315ac7e9b9 to your computer and use it in GitHub Desktop.
Days Old Optional Homework Pt 2.b
# Given your birthday and the current date, calculate your age in days.
# Account for leap days.
#
# Assume that the birthday and current date are correct dates (and no
# time travel).
#
#leap year procedure
def isleapyear(x):
if x % 4 != 0:
return False
elif x % 400 != 0:
return False
elif x % 100 != 0:
return True
else:
return True
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
##
# Your code here.
##
# Test routine
def test():
test_cases = [((2012,1,1,2012,2,28), 58),
((2012,1,1,2012,3,1), 60),
((2011,6,30,2012,6,30), 366),
((2011,1,1,2012,8,8), 585 ),
((1900,1,1,1999,12,31), 36523)]
for (args, answer) in test_cases:
result = daysBetweenDates(*args)
if result != answer:
print "Test with data:", args, "failed"
else:
print "Test case passed!"
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment