题目
我的代码
import datetime
ipt = input()
begin = datetime.datetime(int(ipt[0:4]), int(ipt[4:6]), int(ipt[6:8]))
flag1=0
flag2=0
while True:
if flag1==1 and flag2==1:
break
begin += datetime.timedelta(days=1)
date = str(begin.year)
if begin.month<10:
date = date + "0"
date = date + str(begin.month)
if begin.day<10:
date = date + "0"
date = date + str(begin.day)
if date == date[::-1] and flag1==0:
print(date)
flag1=1
if date == date[::-1] and date[0]==date[2]==date[5]==date[7] and date[1]==date[3]==date[4]==date[6]:
print(date)
flag2=1
使用datetime上大分,防止非法日期的出现,主要要记住datetime的加减:begin += datetime.timedelta(days=1)
© 版权声明
文章版权归作者所有,请勿转载至任何平台。
THE END
暂无评论内容