python 打印日历

import calendar as c
'''
x = c.monthcalendar(2017,11) 使用这个结果打印出日历

s = 1
while s <= 7:
print('周%d '%(s),end= '')
s += 1
print()

print('=================================')

for a in x:

for b in a:

print('%2d '% (b),end = '')
print()
print('-----------------------------------')

'''
x = c.monthrange(2017,5) 使用这个结果打印出日历
print(x)
a = 1
b = x[1]+1
s = 0
while s < x[0]:
print(' ',end = '')
s += 1
for i in range(a,b):
if i % 7 == 7 - x[0]:
print('%2d' % (i))
else:
if i % 7 == x[0]:
print('%2d' % (i))
else:
print('%2d ' % (i), end=' ')

posted @ 2017-11-19 19:43  Bob__Zhang  阅读(694)  评论(0编辑  收藏  举报