命题输入年份,判断其是闰年还是平年 思路输入数据
判断是否为闰年
主函数
#输入年份(4位)
def input_num():
while True:
try:
year=int(input("Input the year(1000-9999): "))
#输入1000-9999内的整数,否则重新输入
if year in range(1000,10000):
return(year)
else:
continue
#非整数抛异常,提示重新输入
except ValueError:
print("The except is not int ")
continue
#判断是否为闰年
def leap_year(year):
#平年能被4整除不能被100整除为闰年
if year%4==0 and year%100!=0:
print("%d is a lear year"%year)
#世纪年(能整除1000)能被400整除为闰年
elif year%100==0:
print("%d is a lear year."%year)
#其它为平年
else:
print("%d is a common year."%year)
def main():
year=input_num()
leap_year(year)
main()
|