鱼C论坛

 找回密码
 立即注册
查看: 1286|回复: 7

[已解决]零基础学python-005讲课后练习-动动手

[复制链接]
发表于 2020-5-13 21:09:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
判断给定年份是否为闰年的代码:
temp = input('请输入一个年份:')
while not temp.isdigit():
    temp = input("抱歉,您的输入有误,请输入一个整数:")
year = int(temp)
if year/400 == int(year/400):
    print(temp + ' 是闰年!')
else:
    if (year/4 == int(year/4)) and (year/100 != int(year/100)):
        print(temp + ' 是闰年!')
    else:
        print(temp + ' 不是闰年!')


请问年份的格式是不是需要界定一下?我输入000,程序也能继续 1589375355(1).jpg
最佳答案
2020-5-13 21:23:08
本帖最后由 liuzhengyuan 于 2020-5-13 21:27 编辑

加一个 if int(temp) <= 0
但是问题是 0 年 也是一个正确的年份呀!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-5-15 23:54:55 | 显示全部楼层
也是哦~~谢谢各位的回答
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-26 05:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表