Meal Time
Suppose that you’re in a country where it’s customary to eat breakfast between 7:00 and 8:00, lunch between 12:00 and 13:00, and dinner between 18:00 and 19:00. Wouldn’t it be nice if you had a program that could tell you what to eat when?
In meal.py
, implement a program that prompts the user for a time and outputs whether it’s breakfast time
, lunch time
, or dinner time
. If it’s not time for a meal, don’t output anything at all. Assume that the user’s input will be formatted in 24-hour time as #:##
or ##:##
. And assume that each meal’s time range is inclusive. For instance, whether it’s 7:00, 7:01, 7:59, or 8:00, or anytime in between, it’s time for breakfast.
Structure your program per the below, wherein convert
is a function (that can be called by main
) that converts time
, a str
in 24-hour format, to the corresponding number of hours as a float
. For instance, given a time
like "7:30"
(i.e., 7 hours and 30 minutes), convert
should return 7.5
(i.e., 7.5 hours).
Hints
-
Recall that a
will assignstr
comes with quite a few methods, per https://docs.python.org/3/library/stdtypes.html#string-methods, includingsplit
, which separates astr
into a sequence of values, all of which can be assigned to variables at once. For instance, iftime
is astr
like"7:30"
, then"7"
tohours
and"30"
tominutes
. -
Keep in mind that there are 60 minutes in 1 hour.
Before You Begin
From the root of your repository execute cd conditionals
So your current working directory is ...
meal.py
where you’ll write your program.
How to Test
Here’s how to test your code manually. At the meal/ $
prompt in your terminal: :
- Run your program with
python meal.py
. Type7:00
and press Enter. Your program should output: - Run your program with
python meal.py
. Type7:30
and press Enter. Your program should output: - Run your program with
python meal.py
. Type12:42
and press Enter. Your program should output: - Run your program with
python meal.py
. Type18:32
and press Enter. Your program should output: - Run your program with
python meal.py
. Type11:11
and press Enter. Your program should output:
Pytest
You can execute the below to check your code using pytest
from the root directory.
A green output from running the test means it was successful. A red output means there is a bug in your code that you need to fix.
How to Submit
From github desktop or the command line, commit your changes and push them to your repository.
Codespaces
If you are using codespaces, you can commit your changes directly from the Codespace interface. Click on the Source Control icon in the left sidebar, then click on the "..." button and select "Commit to main". Enter a commit message and click "Commit".
Codespace terminal or your local terminal.
Note
You will need to have installed git-scm
for this to work locally
At the /conditionals/meal $
prompt in your terminal: