首页 > 编程学习 > 【python】判断闰年

【python】判断闰年

发布时间:2022/8/12 13:44:26
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)
Copyright © 2010-2022 ngui.cc 版权所有 |关于我们| 联系方式| 豫B2-20100000