monthDay = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] count = 0 for i, Day in enumerate(monthDay): for day in range(Day): listDay = list(str(day+1)) listDayInt = [int(num) for num in listDay] if i+1 == sum(listDayInt): count += 1 print(count)