如何制作日历日期簿python

时间:2013-07-07 20:05:35

标签: python python-2.7

好的,所以我应该制作一个日期簿,打印出一个月的所有日子和每月的变化,因为他们有不同的日子,它必须使用列表和两个for循环这里是我所拥有的

monthNames = [ "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]

daysInMonth = ( 0,31,28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )

for i in monthNames:
    for n in daysInMonth:


        print "%3s %8d _________________________________________"%(i,n)

那么如何让它每天打印一行?

1 个答案:

答案 0 :(得分:0)

您正在迭代每个月的每个月。相反,迭代给定月份的天数范围。

for month, days in zip(monthNames, daysInMonth):
    for day in range(1, days + 1):
        print "%3s %8d" % (month, day)