如何使用 Python 判断闰年?
闰年每四年出现一次。对于普通年份,如果它能被四整除,它就被称为闰年,而对于世纪年,它应该能被四百整除。以下 Python 程序显示当年是否是闰年。
示例
yr=int(input('enter year')) if yr%100==0: #century year if yr%400==0: print ('{} is leap year'.format(yr)) else: print ('{} is not leap year'.format(yr)) else: if yr%4==0: print ('{} is leap year'.format(yr)) else: print ('{} is not leap year'.format(yr))
输出
enter year2012 2012 is leap year enter year2018 2018 is not leap year 2000 is leap year enter year1900 1900 is not leap year
广告