Ginger Beer Machine
Suppose that a machine sells bottles of Ginger Beer for 50 cents and only accepts coins in these denominations: 25 cents, 10 cents, and 5 cents.
In a file called ginger_beer_machine.py
, implement a program that prompts the user to insert a coin, one at a time, each time informing the user of the amount due. Once the user has inputted at least 50 cents, output how many cents in change the user is owed. Assume that the user will only input integers, and ignore any integer that isn’t an accepted denomination.
Note
The commandline supports tab completion. You can use tab to complete commands or filenames after typing the first few characters of a command or filename.
Before You Begin
From the root of your repository execute cd src/loops
So your current working directory is ...
ginger_beer_machine.py
where you’ll write your program.
How to Test
Here’s how to test your code manually:
-
Run your program with
and continue prompting the user for coins.python ginger_beer_machine.py
. At yourInsert Coin
: prompt, type25
and press Enter. Your program should output: -
Run your program with
and continue prompting the user for coins.python ginger_beer_machine.py
. At yourInsert Coin
: prompt, type10
and press Enter. Your program should output: -
Run your program with
and continue prompting the user for coins.python ginger_beer_machine.py
. At yourInsert Coin
: prompt, type5
and press Enter. Your program should output: -
Run your program with
because the machine doesn’t accept 30-cent coins! Your program should then continue prompting the user for coins.python ginger_beer_machine.py
. At yourInsert Coin
: prompt, type30
and press Enter. Your program should output: -
Run your program with
python ginger_beer_machine.py
. At yourInsert Coin
: prompt, type25
and press Enter, then type25
again and press Enter. Your program should halt and display: - Run your program with
python ginger_beer_machine.py
. At your Insert Coin: prompt, type25
and press Enter, then type 10 and press Enter. Type25
again and press Enter, after which your program should halt and display:
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 /datatypes $
prompt in your terminal:
Note
Remember to replace "your message here" with a meaningful commit message that describes your changes.