DEV Community

Saeed Adam
Saeed Adam

Posted on

2 1

Python Console Calendar

Welcome to another tutorial.
Today I will show you how to develop console calendar using python.

This requires built in method known as "calendar". The module owns a method "month()" which takes two arguments, the year and the exact month which the user want to display.

import calendar  

year = 1999
month = 2
Print ("The Calendar of\n: ", calendar.month(year, month))

Enter fullscreen mode Exit fullscreen mode

The code above outputs as below

The Calendar of                                                     
February 1999
Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
Enter fullscreen mode Exit fullscreen mode

To develop a bot, one can accept input from user for a year and a month.

import calendar  

year = int(input ("Please enter the Year: ")) # Holds the year

month = int(input ("Please enter the month: "))    # Holds the month 

# display the calendar  
Print ("The Calendar of: ", calendar.month(year, month))  
Enter fullscreen mode Exit fullscreen mode

Output

C:\Users\Ameer_studio\Desktop>py cal.py
Please enter the Year: 1999
Please enter the month: 2
The Calendar of:     February 1999
Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
Enter fullscreen mode Exit fullscreen mode

Thanks for reading🙏

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay