我用python 写了一个判断闰年的代码,想建立一个循环,但是总是无限循环或者没有答案

2025-04-14 15:19:00
推荐回答(1个)
回答1:

def is_leap(year):
    year = int(year)
    return year % 400 == 0 or (year%4==0 and year%100!=0)
    
for i in range(5):
    temp = input('输入你想要的年份')
    while not temp.isdigit():
        temp = input("请输入整数")
    if is_leap(temp):
        print(temp+'是闰年')
    else:
        print(temp+'不是闰年')