|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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 + ' 不是闰年!')
上面段代码是第五讲的课后作业, temp = input("抱歉,您的输入有误,请输入一个整数:"),这里的为什么要用 temp = input?
下面这段代码,根据上面的这段代码整改了一下,请大家帮忙看看有什么地方不适合的,运行了几次没出错。
temp = input('请输入一个年份:')
while not temp.isdigit():
temp = input("抱歉,您的输入有误,请输入一个整数:")
year = int(temp)
if (year % 4 == 0) and (year % 100 != 0) or (year % 400 == 0):
print(temp + "是闰年!")
else:
print(temp + "不是闰年!")
input()
大致的没啥问题
不过建议
- if ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0):
复制代码
打个括号,更简洁易懂一些
|
|