判断任意输入年份是闰年还是普通闰年还是平年

判断任意输入年份是闰年还是普通闰年还是平年

判断输入年份是否为世纪闰年(能被100整除但不能被400整除)或普通闰年(能被4整除但不能被100整除,或者能被400整除)。用户输入一个年份后,程序会判断该年份是世纪闰年、普通闰年还是平年,并输出相应结果。向[小蜜蜂AI][https://zglg.work]网站GTP提问,获取示例代码如下:

python 复制代码
def check_leap_year(year):
    if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
        if year % 100 == 0 and year % 400 != 0:
            return f"{year}年是世纪闰年"
        else:
            return f"{year}年是普通闰年"
    else:
        return f"{year}年是平年"

year = int(input("请输入一个年份: "))
result = check_leap_year(year)
print(result)

运行结果如下:

python 复制代码
请输入一个年份: 2000
2000年是世纪闰年
请输入一个年份: 2024
2024年是普通闰年
请输入一个年份: 2019
2019年是平年
相关推荐
bearpping4 小时前
Nginx 配置:alias 和 root 的区别
前端·javascript·nginx
@大迁世界5 小时前
07.React 中的 createRoot 方法是什么?它具体如何运作?
前端·javascript·react.js·前端框架·ecmascript
January12075 小时前
VBen Admin Select 选择框选中后仍然显示校验错误提示的解决方案
前端·vben
猿界零零七5 小时前
pip install mxnet 报错解决方案
python·pip·mxnet
. . . . .5 小时前
前端测试框架:Vitest
前端
xiaotao1315 小时前
什么是 Tailwind CSS
前端·css·css3
战南诚6 小时前
VUE中,keep-alive组件与钩子函数的生命周期
前端·vue.js
发现一只大呆瓜6 小时前
React-彻底搞懂 Redux:从单向数据流到 useReducer 的终极抉择
前端·react.js·面试
霍理迪7 小时前
Vue的响应式和生命周期
前端·javascript·vue.js