def isYear(year):
if (year%4 == 0) & (year%100 != 0) |(year%400 == 0):
print(f"{year}年是闰年")
else:
print(f"{year}年不是闰年")
year = int(input("请输入一个年份:"))
isYear(year)
lambda表达式版:
leap = lambda x:(x % 4 == 0 and x % 100 != 0) or (x % 400 == 0)
def isLeapYear(year):
if leap(year):
print(f'{year} is a leap year' )
else:
print(f'{year} is NOT a leap year' )
year = int(input("请输入一个年份:"))
isLeapYear(year)