关于python 零基础p005 闰年程序
为什么如下文本,输入任何一个数均输出‘不是闰年’呢#闰年
yea = input('yea:')
year = int(yea)
a = year/4
b = year/100
c = year/400
if type(c) == type(1):
print('yea belongs to leap year')
else:
if (type(a) == type(1)) and (type(b) != type(1)):
print('yea belongs to leap year')
else:
print('yea not belongs to leap year') year = int(input('year : '))
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print('yea belongs to leap year')
else:
print('yea not belongs to leap year')
因为 Python 只要用 / 除法,得到的数据类型一定是 float ,所以你的 if 条件永远不可能满足~
举个例子:
>>>10/2
5.0
>>>type(10/2)
<class "float"> 好的呀 非常感谢
页:
[1]