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))

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理