Python program to print a calendar

import calendar

def print_calendar(year, month):

    # Create a TextCalendar object

    cal = calendar.TextCalendar(calendar.SUNDAY)  # Start week on Sunday

    # Generate the calendar for the given year and month

    month_calendar = cal.formatmonth(year, month)

    # Print the calendar

    print(month_calendar)


if __name__ == "__main__":

    try:

        year = int(input("Enter the year (e.g., 2023): "))

        month = int(input("Enter the month (1-12): "))


        if 1 <= month <= 12:

            print_calendar(year, month)

        else:

            print("Invalid month! Please enter a number between 1 and 12.")

    except ValueError:

        print("Invalid input! Please enter valid year and month values.")

Post a Comment

0 Comments