Project 9 of 20, for Caitlin
Opening Hours Module
One module of opening-hours helpers, imported by every floor of the Clocktower, and Caitlin's board by the front door to show it off.
Sign up free to open itLog in
Act 2 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- CaitlinI want a board by the front door that shows whether every floor is open or shut right now.
- CaitlinThe trouble is every floor has its own copy of the opening-hours code.
- CaitlinSomebody changed the Workshop's copy and now it closes at half past never.
- PaulOkay, that somebody was me. Let's put it in a module, write it once and import it everywhere.
Write hours.py, a module every floor can import. A room's hours are a dictionary of day to (opens, closes), in whole hours on the 24-hour clock. A day that's missing is a day the room is closed.
is_open(hours, when):Trueif the room is open atwhen, adatetime. Open from the opening hour; closed from the closing hour.sign(hours): seven lines for the door, Monday first:Mon 8 till 18, orSun closed.busiest_day(visits): the day name, likeSat, that comes up most in a list of visit times. If days tie, the one seen first. No visits:None.
The board for the front door, main.py, is already written. Run on its own, hours.py prints a quick check of itself; imported, it stays quiet.
Saturday 11:30 at the Clocktower The Studio: open The Makerspace: closed The Workshop: open The Studio's door: Mon 8 till 18 Tue 8 till 18 Wed 8 till 18 Thu 8 till 18 Fri 8 till 18 Sat 8 till 13 Sun closed Busiest in the Studio: Sat
What you learn
What's in it
- Ready-made modules
- Sunday, and a bit
- The shelf of ready-made modules
- A module of your own
- Same name, two jobs
- Only when it's run itself
- What's my name
- How Paul would do it
- Fix Riya's version
- Make the hours module
- Ship it