def is_leap(year):
if year >=1900:
if year%4==0:
if year%100==0:
if year%400==0:
print ("True")
else:
print ("False")
else:
print("True")
else:
print("False")
year = int(input())
print(is_leap(year))
year
小于1900
(该功能的第二行)时,该功能将不会打印任何内容。 编辑:对于您现在给出的示例,这是不正确的。我没有检查仅语法的数学运算。但是请注意,您只检查1900年之后的年份。小于1900的每个输入都将不被处理,并且始终为False:
def is_leap(year):
if year >=1900:
if year%4==0:
if year%100==0:
if year%400==0:
return True
else:
return False
else:
return True
else:
return False
return False
year = input()
print(is_leap(year))
def is_leap(year):
开头吗?我在is_leap(2019)
上通过调用Repl.it运行了此代码,并且运行良好。从function is first class in Python开始,您的最后一次呼叫实际上将打印对象。这意味着,当您调用print(function)
时,将打印函数返回的对象。由于您的函数不返回对象,因此将打印None
类型。