判断年份是否为闰年
def leap_year(year): """输入的year需为字符串""" if year.isdigit() and len(year) == 4: # 是数字并且长度为4位数的话才执行判断否则提示输入错误重新输入 year = int(year) if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0): print("您输入的%s是闰年" % year) else: print("您输入的%s是平年" % year)