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))
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
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))
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
Thanks for reading🙏
Top comments (0)