<jupyter_start><jupyter_text>Days Between DatesThis lesson will focus on one problem: calculating the number of days between two dates. This workspace is yours to use in whatever way is helpful. You might want to keep it open in a second tab as you go through the videos.<jupyter_code>def nextDay(year, month, day):
    """Simple version: assume every month has 30 days"""
    if day < daysInMonth(year,month):
        return year, month, day + 1
    else:
        if month == 12:
            return year + 1, 1, 1
        else:
            return year, month + 1, 1
def dateIsBefore(year1, month1, day1, year2, month2, day2):
    """Returns True if year1-month1-day1 is before
       year2-month2-day2. Otherwise, returns False."""
    if year1 < year2:
        return True
    if year1 == year2:
        if month1 < month2:
            return True
        if month1 == month2:
            return day1 < day2
    return False 
def isLeapYear(year):
	if year % 400 == 0:
		return True
	if year % 100 == 0:
		return False
	if year % 4 == 0:
		return True
	return False
def daysInMonth(year, month):
  day31Month=[1,3,5,7,8,10,12]
  if month in day31Month:
    return 31
  else :
    if month is 2:
      if isLeapYear(year):
        return 29
      else:
        return 28
    else:
      return 30
      
 
def daysBetweenDate(year1, month1, day1, year2, month2, day2):
    """Returns the number of days between year1/month1/day1
       and year2/month2/day2. Assumes inputs are valid dates
       in Gregorian calendar."""
    # program defensively! Add an assertion if the input is not valid!
    if dateIsBefore(year1, month1, day1, year2, month2, day2):
        return "AssertionError"
    days = 0
    while dateIsBefore(year1, month1, day1, year2, month2, day2):
        year1, month1, day1 = nextDay(year1, month1, day1)
        days += 1
    return days
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
	if dateIsBefore(year1, month1, day1, year2, month2, day2) == False:
		return "AssertionError"
	else:
		days = 0
		while dateIsBefore(year1, month1, day1, year2, month2, day2):
			year1, month1, day1 = nextDay(year1, month1, day1)
			days += 1
		return days
def test():
    test_cases = [((2012,9,30,2012,10,30),30), 
                  ((2012,1,1,2013,1,1),360),
                  ((2012,9,1,2012,9,4),3),
                  ((2013,1,1,1999,12,31), "AssertionError")]
    
    for (args, answer) in test_cases:
        try:
            result = daysBetweenDates(*args)
            if result == answer and answer != "AssertionError":
                print ("Test case passed!")
            else:
                print ("Test with data:", args, "failed")
    
        except AssertionError:
            if answer == "AssertionError":
                print ("Nice job! Test case {0} correctly raises AssertionError!\n".format(args))
            else:
                print ("Check your work! Test case {0} should not raise AssertionError!\n".format(args))
test()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10550763105507631, 'fraction_numerical': 0.060716655607166554, 'mean_word_length': 2.4775086505190314, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '167209', 'license': 'MIT', 'n_tokens_mistral': 1047, 'n_tokens_neox': 949, 'n_words': 324, 'path': 'DaysBetweenDate.ipynb', 'repo_name': 'souravgopal25/Data-Structure-Algorithm-Nanodegree', 'size': '3014'}