题目内容: 用户输入一个年份(运行界面提示:“请输入年份”),判断这一年是不是闰年,分别输出True和 False当以 下情况之一满足时,这一年是闰年: (1)年份是4的倍数而不是100的倍数(如2004年是,1900年不是) (2)年份是400的倍数(如2000年是,1900年不是) 示例(只有“2020为输入): 请输入年份2020 闰年判断结果是:True
if((y%4==0 && y%100!=0)||(y%400==0))
return true;
else
return false;
条件已经写得很清楚了,使用if函数判断,可以一次写两个判断,也可以两层if嵌套判断。
year=int(input("请输入一个年份"))
if year%4==0 and year%100!=0 or year%400==0:
print(year,"是闰年")
else:
print(year,"不是闰年")
如有帮助请采纳回答,谢谢
从以下网站弄来的示例代码:https://www.geeksforgeeks.org/python-calendar-module-isleap-method/
# Python program to explain working of isleap() method
# importing calendar module
import calendar
# checking whether given year is leap or not
print(calendar.isleap(2016))
print(calendar.isleap(2001))