YAQ本人 发表于 2020-4-12 16:25:59

python中int和float问题

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 + ' 不是闰年!')



if year/400结果类型不是float吗?为什么会等于int?

qiuyouzhi 发表于 2020-4-12 16:34:31

你又没有用isinstance,这里只是单纯比较的值
15和15.000000000的值是不是相等的?
要明白这一点。

YAQ本人 发表于 2020-4-12 16:38:52

qiuyouzhi 发表于 2020-4-12 16:34
你又没有用isinstance,这里只是单纯比较的值
15和15.000000000的值是不是相等的?
要明白这一点。

谢谢dalao回答

qiuyouzhi 发表于 2020-4-12 16:39:37

YAQ本人 发表于 2020-4-12 16:38
谢谢dalao回答

问题解决了就设个最佳答案吧

YAQ本人 发表于 2020-4-12 16:52:00

qiuyouzhi 发表于 2020-4-12 16:39
问题解决了就设个最佳答案吧

找半天都没看到最佳在哪设置

_2_ 发表于 2020-4-12 16:57:05

qiuyouzhi 发表于 2020-4-12 16:39
问题解决了就设个最佳答案吧

人家不是求助帖了,其实最佳答案也挺不容易的

qiuyouzhi 发表于 2020-4-12 17:05:20

YAQ本人 发表于 2020-4-12 16:52
找半天都没看到最佳在哪设置

现在有了吧
页: [1]
查看完整版本: python中int和float问题