任務(wù)011描述
用Python編寫(xiě)一個(gè)程序,輸入指定的月份和年度,打印出該月份的日歷。
說(shuō)明:可以使用calendar模塊。
分析及示例
Python calendar.month(theyear, themonth, w=0, l=0):
Python的calendar.month(theyear, themonth, w=0, l=0)方法可以返回TextCalendar類的formatmonth()執(zhí)行結(jié)果,返回值以多行文本的形式顯示當(dāng)月的日歷。
l(L的小寫(xiě))可以用于指定每一周占據(jù)的行數(shù)。
示例代碼:
import calendar
y = int(input('Input the year:'))
m = int(input('Input the month:'))
print(calendar.month(y, m))
運(yùn)行結(jié)果:
Input the year:2019
Input the month:1
January 2019
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31