hands-on labIDE in your browser

Opening Hours: and, or and Decisions Inside Decisions

The sign on Bean There's door: weekday and weekend hours, the right closed message before opening and after closing, tomorrow's opening time, and Sam's note when there is one.

time
30 min
checked steps
5
level
Beginner
setup
None

$29.99a month with Pro

Pro opens all 5 steps of this lab and every other lab. Cancel any time.

no account needed · Pro opens all 5 steps

See Pro plans

The job

The door sign is a little screen run by Python. Weekdays Bean There opens 7:00 to 18:00, weekends 8:00 to 16:00. Customers want more than open or closed: when it opens, whether that's today or tomorrow, and Sam's note when Sam has left one.

5 steps, each checked when you finish it

A check runs your work at the end of every step. Hints and the full solution are there if you get stuck.

  1. 1

    Weekend or not

    The hours depend on the day, so the sign starts with one question: is day a weekend day?

    read this step below ↓

  2. 2

    Open or closed

    Now the sign itself.

  3. 3

    What the closed sign says

    "Closed" leaves people guessing.

  4. 4

    Open tomorrow at

    "Closed for today" is honest and not much help at 19:00.

  5. 5

    Sam's note

    Sometimes Sam pins a note to the door: "Back at 2pm", "Card machine down, cash only".

Step 1 as it appears in the lab

The lab’s own text. The hint and the solution stay inside the lab.

Step 1: Weekend or not

The hours depend on the day, so the sign starts with one question: is day a weekend day? Here's the version almost everyone writes first:

weekend = day == "Saturday" or "Sunday"

Set day = "Monday" and print it: Sunday. Every day is the weekend. or joins two complete conditions, and the right-hand side here isn't a comparison, it's just the text "Sunday". Python counts any non-empty text as true, so or hands it back. Each side needs its own comparison:

weekend = day == "Saturday" or day == "Sunday"

In sign.py, keep the answer in weekend and print it:

Weekend: True

The check tries every day of the week.

sign.py, the file you edit6 lines
# The sign on Bean There's door. Weekdays 7:00 to 18:00; Saturday and Sunday 8:00 to 16:00.
day = "Saturday"
hour = 9

# TODO (Step 1): keep whether day is Saturday or Sunday in a variable called weekend, and print it:
#   Weekend: True

what you get

  • An editor and terminal in your browser
  • A check at the end of every step
  • Hints and the full solution
  • Nothing to install or configure

before you start

  • Happy Hour: if, elif, else, and and or

Part of the Learn Python track

Lab 8 of 15. Learn Python by running a café till: receipts, orders, discounts and the Friday rush. Nothing to install.

Questions about this lab

Why is day == 'Saturday' or 'Sunday' always true?

or joins two whole conditions. The right-hand side here is just the text 'Sunday', and any non-empty text counts as True. Write day == 'Saturday' or day == 'Sunday'.

Do I need to install anything?

No. Python runs right in your browser.

What you do in this lab

You build a sign out of decisions: a weekend test with or (and the slip that makes every day a weekend), opening hours that depend on the day, an if inside an if for the closed messages, the next day's hours, and an empty note that counts as False.