avatar Bite 367. Add Pi Day to the calendar

Python has a brilliant but often overlooked module called calendar.

In this Bite we use this module to print out well formatted months and a list of significant dates for each month. 

Just for fun, we always add an entry for Pi Day (π Day) on 3/14.

Learner's Task

The function you will build accepts a year and a list of significant dates. Each significant date is made of a tuple, containing two integers representing the month and day of the year, and a string for the date's description.

Examples of the format the function expects is in the docstring on the starter code.

Print out (do NOT return), a calendar of each month with one of the dates (with the first day of the week being Sunday), followed by a line for each of the events in that month showing day of the week, day of the month then the event description, sorted by day of the week in Monday - Sunday order.

Logically, we could make this match the month printout and start with Sunday rather than Monday,  but that would be a bit trickier to code, so I left it simple for you.

There's nothing stopping you from doing this after you solve the Bite, and showing your work in the Bite forum :)

Always add π Day (3/14) as a date whether it is entered or not. So at a minimum, you will print a calendar for March and a listing for π Day on 3/14. Obviously the day of the week π Day falls on will vary depending on the year.

If the year passed into the function is not valid (an integer between 1 and 9999)  raise an InvalidYear exception.

This custom exception has been supplied for you.

For simplicity, we assume that all significant date (month, day) tuples are valid so there is no need to validate this.

As an extra challenge, there is a calendar function that prints a calendar month. Why not use that instead of saving the calendar to a string and printing it out?

Talking of Pi Day, why not celebrate completing this Bite with another Bite - of yummy Pie!

Example

Perhaps this will be easier with an example.

>>> from calendar_add_pi_day import create_calendar
>>> create_calendar(2000, [(2, 27, 'No Brainer Day')])

Should print:

   February 2000
Su Mo Tu We Th Fr Sa
     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
Sunday: No Brainer Day

   March 2000
Su Mo Tu We Th Fr Sa
        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
Tuesday: π Day

 

NOTE: The calendar accounts for February 29 in leap years. You get this for free - no need to code it!

Keep calm and code in Python!

Login and get coding
go back Intermediate level
Bitecoin 3X

11 out of 13 users completed this Bite.
Will you be the 12th person to crack this Bite?
Resolution time: ~49 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 4.0 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help