snippets.txt 534 B

12345678910111213141516171819202122
  1. # Number of days per month. First value placeholder for indexing purposes.
  2. month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  3. def is_leap(year):
  4. """Return True for leap years, False for non-leap years."""
  5. return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
  6. def days_in_month(year, month):
  7. """Return number of days in that month in that year."""
  8. if not 1 <= month <= 12:
  9. return 'Invalid Month'
  10. if month == 2 and is_leap(year):
  11. return 29
  12. return month_days[month]