python判断闰年

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 ("平年")

猜你喜欢

转载自blog.csdn.net/study_in/article/details/85061138