代码如下:
1 #!/usr/bin/env python2
2 #-*- coding:utf-8 -*-
3 """
4 使用python实现万年历
5 """
6
7 def is_leap_year(year):
8 """
9 判断是否是闰年,返回boolean值
10 """
11 if year/4==0 and year/400 !=0:
12 return True
13 elif year/100 == 0 and year/400 ==0 :
14 return True
15 else:
16 return False
17
18 def getMonthDays(year,month):
19 """
20 获取指定年月的月份有多少天
21 """
22 days = 31 #31天居多,设置为默认值
23 if month == 2 : #2月份要判断是否是闰年
24 if is_leap_year(year):
25 days=29
26 else:
27 days=28;
28 elif month in [4,6,9,11]: #判断小月,只有30天
29 days=30
30 return days
31
32 def getTotalDays(year,month):
33 """<