python打印2020某月的日历_如何在Python 3.6中以月矩阵格式打印日历?

I have created the Indian National calendar function in Python as below,

import calendar

import datetime

'Days in Tamil names. first day start from 0-Monday and 6- sunday. similar to ISO format'

tamil_day = ('திங்கள்','செவ்வாய்','புதன்','வியாழன்','வெள்ளி','சனி','ஞாயிறு')

'months in Tamil names. first month start from 0-Chithirai and 11-panguni. similar to ISO format'

tamil_months = ('சித்திரை','வைகாசி','ஆணி','ஆடி','ஆவணி','புரட்டாசி','ஐப்பசி','கார்த்திகை','மார்கழி','தை','மாசி','பங்குனி')

'''reference date for Indian Saka Era

Saka Era 1876 is equal to 1954-55AD or Saka 1875-76 is equal to 1954

March 22,1954 is Chithirai 1,1876 Saka as Indian new year

'''

saka_year_AD_reference = datetime.date(1954,3,22)

saka_year_reference = 1876

saka_year_offset = 78

tamil_first_day_reference = calendar.firstweekday()

tamil_first_month_reference = tamil_months[0]

'''

number of days in each tamil month

normal year- chithirai-30days;

leap year- chithirai-31 days

'''

days_in_month_normal_year = (30,31,31,31,31,31,30,30,30,30,30,30)

days_in_month_leap_year = (31,31,31,31,31,31,30,30,30,30,30,30)

'Enter the year to print the calendar'

year = 1876

'find the year is leap year or not'

def tamil_leap_year(year):

leap=year+saka_year_offset

return calendar.isleap(leap)

'find the first day in given year'

def tamil_first_day_in_year(year):

offset_compensation = year+saka_year_offset

if tamil_leap_year(year):

return calendar.weekday(offset_compensation,3,21)

else:

return calendar.weekday(offset_compensation,3,22)

def print_year(year):

if tamil_leap_year(year)!=True:

day_count = tamil_first_day_in_year(year)

for i in range(12):

print('\n','{:*^16}'.format(tamil_months[i]),' \n','_______________')

for i in range(1,(1+days_in_month_normal_year[i])):

print('{:<2}'.format(i),"|",'{: <2}'.format(tamil_day[day_count]),'\n',end='')

day_count = day_count+1

if i<=31:

if day_count==7:

day_count = 0

continue

else:

break

else:

day_count = tamil_first_day_in_year(year)

for i in range(12):

print(tamil_months[i],'|')

for i in range(1,(1+days_in_month_leap_year[i])):

print(i,"|",tamil_day[day_count])

day_count = day_count+1

if i<=31:

if day_count==7:

day_count = 0

continue

else:

break

print(print_year(year))

I want to print the output in month wise and as similar to Gregorian calendar similar as below

January February March

Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su

1 2 3 4 5 6 7 1 2 3 4 1 2 3 4

8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11

15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18

22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25

29 30 31 26 27 28 26 27 28 29 30 31

Unfortunately, I am a beginner to Python and I don't know how to make a loop in order to create frame the month table. Could anyone help me to solve this problem?

解决方案

first convert the integer into string and then add positional function as center(). the problem get solved.

thank you

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值