新手求助大神!!!零基础学python第五课动动手1
求助各路大神,零基础学python第五课动动手1题为什么我的结果不管输入什么都显示不是闰年?year = input('请输入年份判断是否为闰年:')
while not year.isdigit():
print("输入有误!")
year = input('请输入一个整数:')
num = int(year)
if isinstance ((num/400),int):
print(year + "是一个闰年。")
else:
if isinstance ((num/4),int) and isinstance ((num/100),float):
print(year + "是一个闰年。")
else:
print(year + "不是一个闰年。") #//1、能整除4且不能整除1002、能整除400
times = 10
while times > 0:
times = times - 1
print('请输入年份',end='')
temp = input()
if temp.isdigit() == False:
print('请输入数字:',end='')
else:
year = int(temp)
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print(year,'是闰年')
else:
print(year,'不是闰年')
else:
print(year,'是闰年')
else:
print(year,'不是闰年')
print('程序结束')
python中的/除法将会得到一个float值,也就是真除
比如说4/2 == 2.0
3/2 = 1.5
所以你的代码中if判断肯定为假
建议用2楼的取余方式来进行判断
页:
[1]