Hand in hand to teach you to use 6 lines of code to make calendar generator

Time:2020-11-23

1. Set production objectives

  • Objectives:
  1. Enter the specified year and month to generate the calendar
  2. It can be run repeatedly

2. Make the required function

Enter the specified year and month → input function

Generate monthly calendar → calendar function

It can be run repeatedly → while


3. Start making

Step 1: load the module

becausecalendarThe function is self-contained in the system and can be loaded directly without PIP installation.

import calendar


Step 2: make the input year and month section

import calendar
while True:#Generally, if no assignment is made, the default is true=int(input('please enter the year:'))#Use the variable year to represent the year, and use int to change the input data into integer type=int(input('please enter the month:'))#The principle is the same as above

Step 3: generate monthly calendar

import calendar
while True:#Generally, if no assignment is made, the default is true=int(input('please enter the year:'))#Use the variable year to represent the year, and use int to change the input data into integer type=int(input('please enter the month:'))#The principle is the same as aboveprint(calendar.month(year,month))#Use`print`The function displays the calendar, and the variables year and month represent the year and month

General production completed, now run to try.


4. First operation

Running screenshot:

Hand in hand to teach you to use 6 lines of code to make calendar generator

Very successful. No error reported


This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint

Recommended Today

The course of using Chinese software of poedit Pro

Poedit pro (formerly known as poedit) is a free (professional version charge), open source and cross platform gettext class (. Po format, gettext is used in the application program for program internationalization) International Translation editor. It is also one of the most widely used software of the same type. At present, it is available in […]