|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
temp = input('请输入年份')
while not isinstance(temp,int):
print('输入错误,请输入一个整数')
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+'不是闰年')
input() 输入的永远是字符串,用 isdigit() 判断是不是整数,改成这样:
- temp = input('请输入年份')
- while not temp.isdigit():
- print('输入错误,请输入一个整数')
- 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+'不是闰年')
复制代码
|
|