import datetime dt = datetime.datetime(2015, 1, 1) happyday_cnt = 0 for i in range(365): nday = datetime.timedelta(days=i) after = dt + nday day_str = "%02d" % after.day day_sum_int = int(day_str[0]) + int(day_str[1]) if day_sum_int == after.month: happyday_cnt += 1 print(happyday_cnt)