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

后来想通过以前学习的,让他循环五次,每次就是一个结果出了五遍停止
print('判断年份是否为闰年')

temp = input('输入你想要的年份')

while not temp.isdigit():

temp = input("请输入整数")

x=1

while x<5:

year = int(temp)

if year/400 == int(year/400):

print(temp+'是闰年')

else:

if(year/4 == int(year/4) and year/100 != int(year/100)):

print(temp+'是闰年')

else:

print(temp+'不是闰年')

x+=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+'不是闰年')

温馨提示:答案为网友推荐,仅供参考
相似回答