Python Perpetual calendar implementation code including running results, python Perpetual Calendar
This article provides examples of how to implement calendar in python for your reference. The details are as follows:
# Coding: utf-8def leap_year (year): # judge the year of the year if year % 4 = 0 and year % 100! = 0 or year % 400 = 0: return True else: return Falsedef getMonthDays (year, month): # obtain the number of days of each year in days = 31 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): # Calculate the week 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) return totalDaysyear = input ("input year :") month = input ("Please input month :") iCount = 0 print "day \ t one \ t Two \ t three \ t 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''
Running effect:
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.