|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
temp = input('请输入年份:')
while not temp.isdigit():
temp = input('抱歉,输入不合法请整数:')
year = int(temp)
if year/400 == int(year/400): #前面已经将year的值转换为整数了,为什么这里要将year/400的值再转换一次呢?
print(temp+' 是闰年')
else:
if (year/4==int(year/4)) and (year/100 != int(year/100)): # 同上
print(temp+' 是闰年')
else:
print(temp+' 不是闰年')
下面是我写的,个人感觉这样读起来更好理解,请大家来给个意见,谢谢(不完全是我写的,是看了上面的代码,才写出来的)
nianfen = input('请输入年份:')
while not nianfen.isdigit():
nianfen = input('输入不合法,请重新输入') #为变量nianfen重新赋值
year = int(nianfen)
if (year%4==0 and year%100!=0) or (year%400==0):
print(nianfen+' 是闰年')
else:
print(nianfen+' 不是闰年') |
|