|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大佬好,请问以下检查是否闰年的代码哪里出了问题,为什么会出现第二次录入数字才能进入循环?
times = 3
print('--------看看是不是闰年-------')
temp = input('请输入一个年份:')
while times > 0:
temp = input()
while not temp.isdigit():
temp = input('输入有误,请重新输入:')
year = int(temp)
times = times - 1
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 + '年' + '不是闰年!')
if times > 0:
print('还可以继续录入哦:', end=' ')
else:
print('没机会咯')
本帖最后由 shangjiecat 于 2020-2-20 23:17 编辑
刚进循环就又要输入了,把第一次的temp刷掉了,应该改为 - temp = input('请输入一个年份:')
- while not temp.isdigit():
- temp = input('输入有误,请重新输入:')
- year = int(temp)
- while times > 0:
- times -= 1
- ...(略去到最后)
- if times > 0:
- temp = input('请输入一个年份:')
- while not temp.isdigit():
- temp = input('输入有误,请重新输入:')
- year = int(temp)
- else:...
复制代码
|
|