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判断闰年与否】
推荐阅读
- c和python可以一起学吗,对于初学者而言python和 c先学哪个好
- 换机助手苹果安卓互传可以吗,苹果和安卓一键换机用什么软件茄子快传并不能
- 零基础自学编程书籍推荐,学编程基础入门要买什么书
- 传奇手游平台,盛大传奇游戏
- 苹果一年几场发布会,苹果新品发布会一年几次
- 安卓游戏iOS游戏兼容嘛,苹果与安卓能不能一起玩
- 软件开发的三个阶段,软件设计分哪几个阶段哪个的主要工作是程序设计
- C语言怎么新建项目,C语言程序怎样建工程
- 游戏大全app,哪个APP小游戏好玩有没有好用的推荐一个看看