0
点赞
收藏
分享

微信扫一扫

MATLAB相关性分析

得一道人 11小时前 阅读 1
python前端

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

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

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)

运行结果如下:

请输入一个年份: 2000
2000年是世纪闰年
请输入一个年份: 2024
2024年是普通闰年
请输入一个年份: 2019
2019年是平年
举报

相关推荐

0 条评论