from datetime import date from dateutil.relativedelta import relativedelta dt = date(2016,1,1) happy = 0 for i in range(1,366): cl = dt-relativedelta(days=i) chk = str(cl.day) if len(chk) == 2: chk = int(chk[0]) + int(chk[1]) else: chk = int(chk) if int(cl.month) == chk: happy +=1 print(str(happy)+"\n")