DEV Community

Saeed Adam
Saeed Adam

Posted on

 

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🙏

Latest comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.