Use python to get the calendar table of a certain year

Hello friends, today I will teach you how to get the calendar of a certain year, let's take a look at the effect first:

It can be seen that the program prints out the calendar for 2022, so how to implement this code,

First, you need to import the calendar module, which is a python standard library and does not need to be downloaded

import calendar

Then, we can use the calendar() function of the calendar to get the calendar of a certain year

print(calendar.calendar(2022))

This code can print the calendar for 2022, but if you want to get more calendars, you can use the input() command 

import calendar
import time
while True:
    a=int(input('Which calendar year do you want to know: '))
    print(calendar.calendar(a))
    time.sleep(1)
    print()

The time module is a decoration, and this module is not needed when writing a program.

The above code can print out the calendar table of a certain year you want to get.

If you want to get the calendar of a certain year and month, you can use the mouth() function of the calendar module.

import calendar

print(caledar.mouth(2022,8)) 

As you can see, this code prints out the calendar for August 2022.

Well, the content of this article is here, thank you for watching! 

Guess you like

Origin blog.csdn.net/hu20100913/article/details/126562924