题目https://www.lanqiao.cn/problems/1562/learning/?page=1&first_category_id=1&sort=students_count&name=%E5%AE%8C%E5%85%A8%E6%97%A5%E6%9C%9F
答案
import datetime
d = datetime.datetime(2001,1,1)
d2 = datetime.datetime(2021,12,31)
delta = datetime.timedelta(days = 1)
cnt = 0
while d <= d2:
num4 = d.year%10
num3 = d.year//10%10
num2 = d.year//100%10
num1 = d.year//1000
num6 = d.month%10
num5 = d.month//10
num8 = d.day%10
num7 = d.day//10
total_num = num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8
for i in range(1,int(total_num)):
if total_num == i*i:
cnt += 1
break
d = d + delta
print(cnt)
977
感想
自己很容易忘记delta