import calendar count = 0 for m in range(1,13): date = calendar.monthrange(2015,m)[1] for d in range(1,date+1): if d < 10: if m == 0 + d: count += 1 else: one_digits = int(str(d)[1]) two_digits = int(str(d)[0]) if m == one_digits + two_digits: count += 1 print(count)