[Tutor] Vending machine program
Mitya Sirenef
msirenef at lightbird.net
Fri Jan 4 19:54:10 CET 2013
On 01/04/2013 06:34 AM, Ghadir Ghasemi wrote:
> H I wanted to create a program called vending machine and I wondered if you could do it so I can find
out how to do it.
> Here is how it should work like:
>
> A food vending machine accepts 10p, 20p, 50p and £1 coins.
> One or more coins are inserted and the current credit is calculated
and displayed.
> A product is selected from those available. The system checks to see
if there is enough credit to purchase the product chosen.
> If there is not enough credit the system displays an error message.
> If there is enough credit it dispenses the product, updates the
credit available and displays the remaining credit.
> Further selections can be made if there is enough credit.
> The vending machine simulation should have five products and prices.
Design, code, test and evaluate a program for this simulation.
>
> Thank you
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
I would suggest a general design with VendingMachine class with these
properties:
- product list (if you don't need to handle running out of products)
- credit (int, in pence)
- method to list products and credit
- method to add to credit
- method to buy a product
A separate class that handles user interface: main loop, accepting the
commands: add amount, select product; a method that runs continuously
until a valid command is provided & then the command is returned. In the
main loop, products are listed, user provides the command, command is
delegated to one of VendingMachine methods and then loop goes back to
the beginning.
Hope this helps, -m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
More information about the Tutor
mailing list