Python练习题:1 用Python判断闰年

temp = input("输入一个数判断是否为闰年:")
flag = 0
time = 3
while flag == 0 and time > 0:
    if temp.isdigit():
        num = int(temp)
        if ((num % 4 == 0) and (num % 100 != 0)) or (num % 400 == 0):
            print("这一年为闰年。")
            flag = 1
        else:
            print("这一年不是闰年。")
            flag = 1
    else:
        print("输入非法,请重新输入:",end = '')
        temp = input()
        time = time - 1

 

你可能感兴趣的:(Python)