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🙏

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide