【python】写一个程序,判断输入年份是否为闰年

写一个程序,判断输入年份是否为闰年

闰年判断方法:能被4整除但不能被100整除,或者能被400整除都是闰年

 

 1 print("----------判断是否为闰年----------")
 2 
 3 temp = input('请输入一个年份:')
 4 while not temp.isdigit():
 5     temp = input("抱歉,您的输入有误,请输入一个整数:")
 6 
 7 year = int(temp)
 8 if year / 400 == int(year / 400):
 9     print(temp+'是闰年!')
10 else:
11     if(year / 4 == int(year / 4)) and  (year / 100 != int(year / 100)):
12         print(temp+'是闰年!')
13     else:
14         print(temp+'不是闰年!')

 

posted @ 2020-03-17 20:27  mirackiller  阅读(7468)  评论(0编辑  收藏  举报