|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
temp = input('请输入一个年份:')
year = int(temp)
while not temp.isdigit():
temp = input('对不起,您的输入有误,请重新输入:')
while year:
if year/400 == int(year/400):
print ('这是闰年')
temp = input('请输入一个年份:')
year = int(temp)
else:
if year/4 == int(year/4) and year/100 != int(year/100):
print ('这是闰年')
else:
print ('这不是闰年')
temp = input('请输入一个年份:')
year = int(temp)
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
============================ RESTART: D:/桌面文件/算闰年.py ===========================
请输入一个年份:-20
对不起,您的输入有误,请重新输入:99
这是闰年
请输入一个年份:99
这不是闰年
请输入一个年份:
我想问一下为什么第一次输入了错误的数据,再次输入同样的年份得出的结果会不一致?
因为你在第一次,“对不起,您的输入有误,请重新输入:99“时 只给temp赋值,并没有给year赋值,这时候year还是-20,不会等于99
|
|