|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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 + ' 不是闰年!')
我想加入 如果输入年份不是闰年的 循环和次数,不知该如何写?做过如下尝试,但是不行:
times = 3
temp = input('请输入一个年份:')
while not temp.isdigit():
temp = input('请输入一个整数:')
year = int(temp)
while (not year/400 == int(year/400) or\
((year/4 == int(year/4)) and (year/100 != int(year/100))))\
and (times > 0):
print(temp + '不是闰年')
print('再试一次:')
if times < 1:
print('机会用完了')
times = times - 1
print('游戏结束') |
|