首先,说一下判断闰年的方法吧。
方法是:如果年份能被4整除但不能被100整除,则为闰年;如果年份能被400整除也为闰年。
若输出结果的年份与文字之间没有空格,如下图所示,代码如下:
year =int(input("请输入一个4位数字的年份:"))
if year%400==0 or year%4==0 and year%100!=0:
print(f'{year}是闰年')
else:
print(f'{year}不是闰年')
若输出结果的年份与文字之间有空格,如下图所示,代码如下:
year =int(input("请输入一个4位数字的年份:"))
if year%400==0 or year%4==0 and year%100!=0:
print(year,"是闰年")
else:
print(year,"不是闰年")