定义一个函数leapyear,判断一个年份是否是闰年。在主函数中输入一个年份,输出它是否是闰年。
闰年判定标准:年份能被4整除,但不能被100整除;或者年份能被400整除;
测试用例1:
输入:
2018
输出:
2018不是闰年
测试用例2:
输入:
2024
输出:
2024是闰年
def leapyear(year):
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
return True
else:
return False
year = int(input(""))
if leapyear(year):
print(year, "是闰年")
else:
print(year, "不是闰年")