代码出问题在哪里?
while True:print('请输入一个年份(按a退出):',end='')
year = input()
if year.lower() == 'a':
break
elif not year.isdigit():
print('抱歉,您的输入有误',end='')
continue
temp = int(year)
if temp/400 == int(temp/400):
print(year + '是闰年!')
else:
if (temp/4 == int(temp/4)) and (temp/100 != temp/100):
print(year + '是闰年!')
else:
print(year + '不是闰年!')
while 1 == 1:
print('请输入一个整数(按q退出):',end='')
temp = input()
if temp.lower()=='q':
break
elif not temp.isdigit():
print('抱歉,您的输入有误,',end='')
continue
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 (temp/4 == int(temp/4)) and (temp/100 != int(temp/100)): 你这两段代码一摸一样啊?有区别吗? 会计的会怎么念 发表于 2020-4-6 12:27
你这两段代码一摸一样啊?有区别吗?
刚开始我也没看出来,第一段代码判断的时候忘记写int()了
页:
[1]