from datetime import datetime, timedelta today = datetime(2015,1,1) cnt = 0 for i in range(365): newday = today + timedelta(days=i) if newday.month == sum(map(int, tuple(str(newday.day)))): cnt += 1 print(cnt)