Python 的 calendar 库中封装好了一个方法 isleap() 来实现判断是否为闰年:
>>> import calendar
>>> print(calendar.isleap(2000))
True
>>> print(calendar.isleap(1900))
False
根据用户输入判断:
import calendar
year = int(input("请输入年份:"))
check_year=calendar.isleap(year)
if check_year == True:
print ("闰年")
else:
print ("平年")