from datetime import datetime,timedelta current = datetime(2015,1,1) happy_day = 0 while True: month = current.month day = current.day digit10 = day // 10 digit1 = day % 10 current+=timedelta(1) if month == digit10 + digit1: happy_day+=1 if month == 12 and day == 31: break print(happy_day)