python积木编程判断闰年,Python判断闰年与否

1,Python判断闰年与否year = 2009is_run_nian = 0if year % 4 != 0:is_run_nian = 0elif year % 4 == 0 and year % 100 != 0:is_run_nian = 1elif year % 100 == 0 and year % 400 == 0:is_run_nian = 1print is_run_niandef leap(year): if year % 400 == 0: return true else: if year % 100 == 0: return false else: if year % 4 == 0: return true else: return false
2,用python编写程序判断闰年# Leap Year Checkif year % 4 == 0 and year % 100 != 0:print(year, "是闰年")elif year % 100 == 0:print(year, "不是闰年")elif year % 400 ==0:print(year, "是闰年")else:print(year, "不是闰年")year = 2009 is_run_nian = 0 if year % 4 != 0: is_run_nian = 0 elif year % 4 == 0 and year % 100 != 0: is_run_nian = 1 elif year % 100 == 0 and year % 400 == 0: is_run_nian = 1 print is_run_nian
3,利用python算闰年12345678910 deftotal_days(start_year, end_year): T =0 fork1 inrange(start_year, end_year): if(k1 %4) ==0and(k1 %100) !=0or(k1 %400) ==0: T+=1 print("ruan nian "+str(k1)) else: print(str(k1)+"bushi ruinian") print(str(T)+"run nian you duoshaotian ") returnT*366+(end_year-start_year-T)*365#加入了排错#python 2.5try:begin = int(raw_input("Starting year : "))end = int(raw_input("Ending year : "))if begin > end:raise Exceptionexcept Exception:print "Bad input!"exit()total = 0for year in xrange(begin, end):if (year%4 == 0 and year%100 != 0) or year%400 == 0:print year, "is a leap year"total += 1else:print year, "is not a leap year"print "Total number of leap years :", total#貌似楼上C的语法和python的搞混了...【python积木编程判断闰年,Python判断闰年与否】

    推荐阅读