You can do all sorts of things with the
import calendar year = int(raw_input('Enter year: ')) month = int(raw_input('Enter month number: ')) print(calendar.monthrange(year, month))
This considers leap years just fine, too.
Enter year: 2012 Enter month number: 2 29
solved Python amount of days in a month with a given year and month? [closed]