242. Python Program to Check If a Shop Is Open
EasyPhase 1 · Warm-up
You know input(), if with else, and and and or. That is all you need here.
Overview
Maps and shop websites show "Open" or "Closed" next to a shop's name. The program behind it checks the day and the time against the opening hours.
Problem Statement
Amara owns a small book shop. The opening hours are:
- Monday to Friday: the shop opens at 9:00 and closes at 18:00.
- Saturday and Sunday: the shop opens at 10:00 and closes at 16:00.
The hour is a whole number on a 24-hour clock: 9 means 9:00 in the morning, and 18 means 6:00 in the evening. At the closing hour the shop is already closed.
Read the day and the hour. Print Open if the shop is open at that hour, or Closed if it is not.
Steps
- Read the day as text, and read the hour as a whole number.
- Check if the day is
SaturdayorSunday. - On a weekend day, the shop is open when the hour is 10 or more and less than 16.
- On any other day, the shop is open when the hour is 9 or more and less than 18.
- Print
OpenorClosed.
Examples
Example 1. Input:
Monday
17
gives:
Open
Why: Monday is a weekday, and 17 is 9 or more and less than 18. So the shop is open.
Example 2. Input:
Sunday
9
gives:
Closed
Why: Sunday is a weekend day, and the shop opens at 10 then. 9 is less than 10, so the shop is still closed.
Input
Two lines:
- The day, written with a capital first letter, like
MondayorSunday. - The hour, a whole number from 0 to 23.
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Output
One line: Open or Closed. The tests try 6 different inputs, also the opening and closing hours.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.