输入年份,判断其是闰年还是平年
输入数据
整数
1000-9999之间的整数
超范围,重新输入
非整数
重新输入
判断是否为闰年
闰年
能被4整除且不能被100整除
能被100整除
非闰年
主函数
调用输入函数
显示判断结果
#输入年份(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()
联系客服