title: Days Between Dates (Python)
body: <p>I am trying to solve this optional problem on Udacity's CS-101 course - it asks to calculate number of days between two dates. My code works for all the test cases but for some reason it doesn't work for the case 1 (1st January 2012 - 28th February 2012), it returns 56 however the actual answer is 58. I am not able to wrap by head around that, any suggestions will be highly appreciated.</p>
  
  <pre><code>def leap_year(year):
      if year % 4 != 0:
          return "Common Year"
      elif year % 100 != 0:
          return "Leap Year"
      elif year % 400 != 0:
          return "Common Year"
      else:
          return "Leap Year"
  
  def days_in_month(month):
      months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
      i = 0
      days = 0
      while i &lt;= month:
          days += months[i- 1]
          i += 1
      return days
  
  
  def daysBetweenDates(year1, month1, day1, year2, month2, day2):
      i = year1
      leap_count = 0
      while i &lt;= year2:
          if leap_year(i) == "Leap Year":
              leap_count += 1
          i += 1
      return ((year2 - year1) * 365 + (days_in_month(month2) - days_in_month(month1)) + (day2 - day1)) + leap_count
  
  # 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()
  </code></pre>