鱼C论坛

 找回密码
 立即注册
查看: 2321|回复: 5

[已解决]为什么我无论输入什么都会显示

[复制链接]
发表于 2020-2-18 14:06:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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+'不是闰年')
最佳答案
2020-2-18 14:10:09
JomQ 发表于 2020-2-18 14:09
请各位大佬指教,谢谢

input() 输入的永远是字符串,用 isdigit() 判断是不是整数,改成这样:

  1. temp = input('请输入年份')
  2. while not temp.isdigit():
  3.     print('输入错误,请输入一个整数')
  4.     temp = input('请输入年份')
  5. year = int(temp)
  6. if year/400 == int(year/400):
  7.     print(temp+'是闰年')
  8. else:
  9.     if year/4 == int(year/4) and year/100 != int(year/100):
  10.         print(temp+'是闰年')
  11.     else:
  12.         print(temp+'不是闰年')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-2-18 14:08:56 | 显示全部楼层
就是无论我输入什么都会显示“输入错误,请输入一个整数”
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-18 14:09:23 | 显示全部楼层
input() 输入的永远是字符串,用 isdigit() 判断是不是整数,改成这样:

  1. temp = input('请输入年份')
  2. while not temp.isdigit():
  3.     print('输入错误,请输入一个整数')
  4.     temp = input('请输入年份')
  5. year = int(temp)
  6. if year/400 == int(year/400):
  7.     print(temp+'是闰年')
  8. else:
  9.     if year/4 == int(year/4) and year/100 != int(year/100):
  10.         print(temp+'是闰年')
  11.     else:
  12.         print(temp+'不是闰年')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-18 14:09:33 | 显示全部楼层
请各位大佬指教,谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-18 14:10:09 | 显示全部楼层    本楼为最佳答案   
JomQ 发表于 2020-2-18 14:09
请各位大佬指教,谢谢

input() 输入的永远是字符串,用 isdigit() 判断是不是整数,改成这样:

  1. temp = input('请输入年份')
  2. while not temp.isdigit():
  3.     print('输入错误,请输入一个整数')
  4.     temp = input('请输入年份')
  5. year = int(temp)
  6. if year/400 == int(year/400):
  7.     print(temp+'是闰年')
  8. else:
  9.     if year/4 == int(year/4) and year/100 != int(year/100):
  10.         print(temp+'是闰年')
  11.     else:
  12.         print(temp+'不是闰年')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-18 14:16:02 | 显示全部楼层
一个账号 发表于 2020-2-18 14:09
input() 输入的永远是字符串,用 isdigit() 判断是不是整数,改成这样:

谢谢,大概明白了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-3-2 20:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表