第005讲,动动手1,为什么不能这样写?
这样写为什么不对?print("-----------------判断是否为闰年---------------------")
temp = input("请输入一个年份:")
while not temp.isdigit():
temp = input("抱歉,您的输入有误,请输入一个整数:")
year = int(temp)
if isinstance(year/400,int) == True:
print(temp + '是闰年')
else:
if (isinstance(year/4,int) == Ture) and (isinstance(year/100,int) == False):
print(temp + '是闰年!')
else:
print(temp + ' 不是闰年!')
/永远返回的是小数,6/3他也会返回2.0
应该用//或者取余 本帖最后由 TJBEST 于 2020-4-8 11:34 编辑
year/400 结果是 float型 无论能否整除 所以你这种方法没戏。 10/2 结果是 5.0不是5 10//2才是5 但是 11//2也是5所以这条路行不通 乖乖用%运算吧
觉得我说的对,受累点个采纳
页:
[1]