Teacher's Guide
Chapter 9 / Level 4: Calendar Module
Teaching Objective:
- Student understands the uses and implementations of the calendar module
- Learns how to produce and manipulate calendars using the various calendar functions
- Understands the correct ways to format and adjust the calendars so they may be displayed properly on screen
Guide
In this exercise we’ll be working with the calendar module, similar to the datetime module, you can work with dates but with the perspective of a calendar. To activate the calendar module write import calendar, this will give you access to several calendar functions and modules. For the purposes of this exercise, we’ll be using the following:
calendar.calendar():Displays the full calendar for the year, takes one (1) argument, that being the year you would like to display.calendar.month():Displays a calendar for a single month, takes two (2) arguments, the year and the month.calendar.isleap():Checks if a year is a leap year, takes one (1) argument, that being the year to check.calendar.leapdays():Checks the number of leap days accumulated across years, takes two (2) arguments being the years spanning the period you would like to check.itermonthdays():UsesCalendar()class, iterates through all the days in the month, takes two arguments, the year and month.itermonthdates():UsesCalendar()class, iterates through all the dates in the month, takes two arguments, the year and month.monthdayscalendar():UsesCalendar()class, iterates through all the weeks in the month, takes two arguments, the year and month. Stores the data in a nested list.monthdays2calendar():Same as previous function but it stores weeks and days together in a two dimensional list.
In this level we’ll be working with setting up timetables and distribution dates using the calendar module functions.
First walk to the gold X and set up a variable named cal, add to it the calendar.calendar() function and set 2026 as an argument. Use the display() function to reviewthe full calendar year.
cal = calendar.calendar(2026)
await player.display(cal)
Walk to the light X mark and use the read() function to read the memo, set up the year and month variables and populate them with the information you read. Create a variable named calendar_month and set the value of calendar.month() with the year and month variables as arguments.
calendar_month = calendar.month(year, month)
Walk to dark X mark over green carpet and create the variable leap_year and store the value of calendar.isleap() with 2026 as an argument. Create variable leap_days and store the value of calendar.leapdays() and add 2026 and 2027 as arguments. Use the pre-written write function and add leap_year and leap_days as arguments.
await player.write(
"Leap Year Status: %s \nNumber of leap days since project start: %s"
% (leap_year,leap_days))
Walk to the dark X mark over the red carpet and create a variable named dates and set it up as a calendar object by setting calendar.Calendar() as the value. Set up a variable named day_roster and set the value as an empty string.
dates = calendar.Calendar()
day_roster =""
Create two for loops, one with itermonthdays() with year and month as arguments and one with day in dates.itermonthdates() with the same arguments. Each has their own entry and day_roster edits with each loop cycle. Once they are looped, use the day_roster variable with the pre-written display() variable.
for dayin dates.itermonthdays(year, month):
entry ="Day: %s \n" % (day)
day_roster += entry
for dayin dates.itermonthdates(year, month):
entry ="%s \n" % (day)
day_roster += entry
await player.display(
"Updated Project Schedule: \n%s" % (day_roster))
Walk to the dark X mark over the blue carpet and create another variable named dates and set it up as a calendar object by setting calendar.Calendar() as the value. Resert the month variable and set it to 7 , and a variable named week_roster and set the value as an empty string.
weeks = calendar.Calendar()
month =7
week_roster =""
Create two for loops, one with weeks.monthdayscalendar() with year and month as arguments and one with day in weeks.monthdays2calendar() with the same arguments. Each has their own entry and week_roster edits with each loop cycle. Once they are looped, use the week_roster variable with the pre-written display() variable in order to complete the level.
for dayin weeks.monthdayscalendar(year, month):
entry ="%s \n" % (day)
week_roster += entry
for dayin weeks.monthdays2calendar(year, month):
entry ="%s \n" % (day)
week_roster += entry
await player.display(
"Follow up timetables: \n%s" % (week_roster))
Map overview and path

Code Solution
import player
import calendar
player.turn_left()
player.move_forward(2)
player.turn_left()
cal = calendar.calendar(2026)
await player.display(cal)
player.turn_left()
player.move_forward(4)
player.turn_right()
await player.read()
year = 2026
month = 6
# Populate calendar month
calendar_month = calendar.month(year, month)
await player.display(calendar.month(year, month))
player.turn_left()
player.move_forward()
player.turn_right()
# Set up variables to produce data
leap_year = calendar.isleap(2026)
leap_days = calendar.leapdays(2020, 2027)
await player.write(
"Leap Year Status: %s \nNumber of leap days since project start: %s"
% (leap_year,leap_days))
player.turn_left()
player.turn_left()
player.move_forward(2)
player.turn_right()
player.move_forward(2)
player.turn_right()
# Set up calendar object and roster
dates = calendar.Calendar()
day_roster = ""
# Set up for loop in order to iterate the work days
for day in dates.itermonthdays(year, month):
entry = "Day: %s \n" % (day)
day_roster += entry
for day in dates.itermonthdates(year, month):
entry = "%s \n" % (day)
day_roster += entry
await player.display(
"Updated Project Schedule: \n%s" % (day_roster))
player.turn_right()
player.move_forward(5)
player.turn_left()
weeks = calendar.Calendar()
month = 7
week_roster = ""
for day in weeks.monthdayscalendar(year, month):
entry = "%s \n" % (day)
week_roster += entry
for day in weeks.monthdays2calendar(year, month):
entry = "%s \n" % (day)
week_roster += entry
await player.display(
"Follow up timetables: \n%s" % (week_roster))