import datetime a=datetime.date(2015,1,1) c=0 while a!=datetime.date(2016,1,1): s=str(a.day) if len(s)==1: if a.month==a.day: c+=1 if len(s)==2: if a.month==(int(s[0])+int(s[1])): c+=1 a+=datetime.timedelta(days=1) print(c)