The provided code is a Python script that simulates a coffee machine program. It allows users to interact with the coffee machine by selecting drinks from a menu, checking the machine's resources, making payments, and ultimately receiving their desired drinks. The program operates in a loop until the user decides to turn it off.
-
The code imports three classes:
Menu
,CoffeeMaker
, andMoneyMachine
. -
It initializes instances of these classes:
menu
,coffee_maker
, andmoney_machine
. -
The program uses a
while
loop to keep running until the variableis_on
becomesFalse
. -
Inside the loop, it presents the user with a list of available drink options retrieved using
menu.get_items()
. The user is prompted to enter their choice. -
If the user inputs "off," the
is_on
variable becomesFalse
, and the program terminates. -
If the user inputs "report," the program calls
coffee_maker.report()
andmoney_machine.report()
to display the current status of the coffee machine's resources and profits. -
If the user selects a specific drink, the program checks if there are sufficient resources to make that drink using
coffee_maker.is_resource_sufficient(drink)
. It also checks if the user has enough money to purchase the drink usingmoney_machine.make_payment(drink.cost)
. -
If both resource sufficiency and payment are met, the program proceeds to make the coffee using
coffee_maker.make_coffee(drink)
.