import calendar count = 0 for m in range(1,13): date = calendar.monthrange(2015,m)[1] for d in range(1,date+1): if m == sum([int(s) for s in str(d)]): count += 1 print(count)