[Python]对称日!

def check(year):
    if (year%4 == 0 and year%100 != 0) or year%400 == 0:
        return True
    else:
        return False

month_day = [0,31,29,31,30,31,30,31,31,30,31,30,31]
tot = 1
dp = {}

for y in range(2022,10000):
    y_str = str(y)
    m = int(y_str[-1:-3:-1])
    d = int(y_str[-3::-1])
    if 1 <= m and m <= 12:
        if month_day[m] >= d and (m != 2 or check(y)):
            print(y,".",sep=(""),end=(""))
            if m < 10:
                print("0",end=(""))
            print(m,".",sep=(""),end=(""))
            if d < 10:
                print("0",end=(""))
            print(d)
            
            tot += 1
            dp[y]=[y,m,d]

print("这个世界上一共只会有",tot,"次对称日了!\n我们又能见到几次呢?")

cnt = 0
now = int(input("请问今年是?"))
life = int(input("请问您的阳寿还有几年?"))
now_life = now + life

for y in range(now,now_life+1):
    if y in dp.keys():
        cnt += 1

print("如果你估计的不错的话!\n那你还有",cnt,"次对称年可以见到!")
posted @ 2021-12-02 20:02  Rosyr  阅读(54)  评论(0编辑  收藏  举报