Page 313 - CTS - CSA TP - Volume 2
P. 313

COMPUTER SOFTWARE APPLICATION - CITS




           Output:












           TASK 2:  Calendar Module
           import calendar
           # Example 6: Display Calendar
           year = int(input(“Enter the Year: “))

           month = int(input(“Enter the Month: “))
           cal = calendar.month(year, month)
           print(f”Calendar for {calendar.month_name[month]} {year}:\n{cal}”)
           1  Importing the calendar module:





           •  This line imports the built-in calendar module, which provides functions to work with calendars.
           2  Getting User Input for Year and Month:







           •  These lines prompt the user to enter the year and month for which they want to display the calendar.
           •  The input function takes user input as a string, and int is used to convert it to integers.

           3  Generating Calendar:





           •  This line uses the month function from the calendar module to generate a formatted   calendar  as  a  string
              for the specified year and month.
           •  The result is stored in the variable cal
           4  Printing the Calendar:






           •  This line prints the formatted calendar.
           •  The f-string includes the name of the entered month and the entered year for clarity.

           •  The calendar.month_name[month] is used to get the name of the month based on the entered numeric value.
           •  The formatted calendar string (cal) is printed.
              In summary, the code takes user input for the year and month, uses the calendar module to generate a
              formatted calendar, and prints the calendar with additional information for better readability.



                                                           298

                              CITS : IT & ITES - Computer Software Application - Exercise 136
   308   309   310   311   312   313   314   315   316   317   318