python判断闰年程序是什么

2025-10-27
网站建设限时活动促销

本教程操作环境:windows7系统、python3.9版,DELL G3电脑。

python判断闰年程序:

以下实例用于判断用户输入的年份是否为闰年:

实例

立即学习“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 语句来实现:

执行以上代码输出结果为:

输入一个年份: 20002000 是闰年
输入一个年份: 20112011 不是闰年

标签: python判断闰年

本文地址:https://www.lifejia.cn/news/213563.html

免责声明:本站内容仅用于学习参考,信息和图片素材来源于互联网,如内容侵权与违规,请联系我们进行删除,我们将在三个工作日内处理。联系邮箱:cloudinto#qq.com(把#换成@)