V.Vidhya Logo

V.Vidhya

Calendar


Build a text-based Full-Year Calendar Generator, which based on a user-specified year, prints all twelve months with correctly aligned weekday headings and dates.

Instructions
  • Prompt the user for the year (e.g. 2025).

  • Before printing the calendar, you’d need to determine the first day of the week for January 1st of the given year.

    • Use the simplified version of Zeller's congruence algorithm to determine that:

      first_day = ((Y-1) + (Y-1)//4 - (Y-1)//100 + (Y-1)//400 + 1) % 7

      • Where Y is the year
      • All divisions here are integer divisions //, discarding any remainder
      • The result gives the day of the week for January 1st of the given year as an integer value, where 0 - Sunday … 6 - Saturday
  • Determine the day of the week for the first day of subsequent months:

    first_day_of_next_month = (first_day_of_previous_month + days_in_month(m, y)) % 7

    • Where days_in_month(m, y) is the number of days in month m of year y
    • The result gives the weekday index for the first day of the next month as an integer value, where 0 - Sunday … 6 - Saturday
  • Print each month with the correct number of days and align the dates under the appropriate weekday headers (Sun, Mon, Tue, Wed, Thu, Fri, Sat).

  • Handle the varying number of days in each month and correctly align the dates under the weekday headers.

  • Consider leap years when determining the number of days in February.

  • Ensure that the calendar is properly formatted and visually appealing.

Expected Output
Enter year for calendar: 2025

# Month 1: January #
Sun Mon Tue Wed Thu Fri Sat
             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  29  30  31 

# Month 2: February #
Sun Mon Tue Wed Thu Fri Sat
                         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

...
(then Month #3 through Month #12 in the same layout)


Feel free to implement additional features to enhance the user experience.


Prev Post
Chatbot
Next Post
TicTacToe Game