import datetime date = datetime.datetime.strptime("2015/01/01", "%Y/%m/%d") ans = 0 for i in range(365): m = date.month d = date.day if m == d%10 + d//10: ans += 1 date += datetime.timedelta(days=1) print(ans)