This article mainly for you in detail the Python calendar implementation code, including the operation results, with a certain reference value, interested in small partners can refer to
The example of this article for you to share the Python implementation of the calendar of the specific code for everyone to refer to, the specific content as follows
#coding: Utf-8def leap_year (year): #判断平瑞年 if year%4==0 and year%100!=0 or year%400==0: return True else: return falsedef getmonthdays (year,month): #得到每个年份每月的天数 days = + If month = = 2: if Leap_year (year): days=29 Else: days=28 elif month==4 or month==6 or month==9 or month==11: days=30 return Daysdef gettotaldays (year,month): #计算星期 totaldays=0 for i in range (1,year): if Leap_year (i): Totaldays + = 366 Else: totaldays + 365 for i in range (1,month): totaldays +=getmonthdays (year,i) C21/>return totaldaysyear=input ("Enter year:") month = input ("Enter month:") ICount = 0print "t \ t two \ three \ four \ t five \ t Six" i=1for I in Range (( Gettotaldays (year,month)%7) +1): print ' \ t ', icount+=1for i in range (1,getmonthdays (year,month) +1): Print I, ' \ t ', iCount +=1 if icount%7 = = 0: print '
Operating effect: