2018-04-08 回答
#!/usr/bin/evn python
def simplecalendar():
daysofmonth=daysofmonths=daysofyears=month=year=0
yearfun=lambda year:year % 400 ==0 or year % 4==0 and year % 100 !=0
print "*"*30,"calendar","*"*30
year=input("enter year: ")
leap=yearfun(year)
month=input('enter month: ')
assert month in range(1,13),"month must in 1-12"
if month==2:
daysofmonth=29 if leap else 28
else:
daysofmonth=30 if month in [4,6,9,11] else 31
for i in range(1,month):
if i==2:
daysofmonths+=29 if leap else 28
else:
daysofmonths+=30 if i in [4,6,9,11] else 31
for i in range(1900,year):
daysofyears+=366 if yearfun(i) else 365
daysofyears+=daysofmonths
weak=1+daysofyears%7
print "sun\tmon\ttue\twed\tthu\tfri\tsat"
print "\t"*weak,
for i in range(1,daysofmonth+1):
weak+=1
if weak%7!=0:
print i,'\t',
else:
print i,'\n',
if __name__=='__main__':
simplecalendar()