我是靠谱客的博主 清脆眼神,最近开发中收集的这篇文章主要介绍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

最后

以上就是清脆眼神为你收集整理的python打印2020某月的日历_如何在Python 3.6中以月矩阵格式打印日历?的全部内容,希望文章能够帮你解决python打印2020某月的日历_如何在Python 3.6中以月矩阵格式打印日历?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部