from datetime import datetime, timedelta count = datetime(2015, 1, 1) last_day = datetime(2015, 12, 31) counter = 0 while count <= last_day: day_str = str(count.day) place_of_one = int(day_str[0]) tens_place = int(day_str[1]) if count.day >= 10 else 0 if place_of_one + tens_place == count.month: # HAPPY DAY! counter += 1 count += timedelta(days=1) print(counter)