from datetime import date, timedelta #日付を取得 start = date(2015,1,1) end = date(2015,12,31) current = start counter = 0 while current <= end: #月と日にちの数値を取得 month = current.month d_tens = current.day//10 d_ones = current.day%10 #ハッピーデイを探す if (month == (d_tens + d_ones)): counter +=1 #翌日へ current += timedelta(days=1) else: current += timedelta(days=1) print(counter)