#coding:utf-8
defleap_year(year):#判断平瑞年
ifyear%4==0andyear%100!=0oryear%400==0:
returnTrue
else:
returnFalse
defgetMonthDays(year,month):#得到每个年份每月的天数
days=31
ifmonth==2:
ifleap_year(year):
days=29
else:
days=28
elifmonth==4ormonth==6ormonth==9ormonth==11:
days=30
returndays
defgetTotalDays(year,month):#计算星期
totalDays=0
foriinrange(1,year):
ifleap_year(i):
totalDays+=366
else:
totalDays+=365
foriinrange(1,month):
totalDays+=getMonthDays(year,i)
returntotalDays
year=input("输入年份:")
month=input("请输入月:")
iCount=0
print"日\t一\t二\t三\t四\t五\t六"
i=1
foriinrange((getTotalDays(year,month)%7)+1):
print'\t',
iCount+=1
foriinrange(1,getMonthDays(year,month)+1):
printi,'\t',
iCount+=1
ifiCount%7==0:
print''