python判断闰年程序:
以下实例用于判断用户输入的年份是否为闰年:
实例
# -*- coding: UTF-8 -*- # Filename : test.py # author by : www.runoob.com year = int(input("输入一个年份: ")) if (year % 4) == 0: if (year % 100) == 0: if (year % 400) == 0: print("{0} 是闰年".format(year)) # 整百年能被400整除的是闰年 else: print("{0} 不是闰年".format(year)) else: print("{0} 是闰年".format(year)) # 非整百年能被4整除的为闰年 else: print("{0} 不是闰年".format(year))
我们也可以使用内嵌 if 语句来实现:
执行以上代码输出结果为:
输入一个年份: 2000 2000 是闰年
输入一个年份: 2011 2011 不是闰年
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)