python简单判断输入年份是否为闰年

"""
闰年:
能被4整除,而且不能被100整除
或者
能被4整除,而且又能被400整除
"""
while 1:
    this_time = int(input("请输入年份:"))
    #条件1
    condition1 = this_time%4 == 0 and this_time%100 != 0
    #条件2
    condition2 = this_time%4 == 0 and this_time%400 == 0
    if (condition1 or condition2):
        print("%d年是闰年"%(this_time))
    else:
        print("%d年不是闰年"%(this_time))
相关文章
相关标签/搜索