Starting a Coffee Coffee machine

In very simple organizational languages, and one in harmony with its own and diversity and coding opportunities as complex as they arrive. While a number of projects and tutorials in the Python codes are based on the Python, in this article, we will learn to build a Coffee Coffee machine program. This article will provide comprehension and media practices and psythimes, and Python dictionaries and will serve as a basis for complex codes (in the consecutive article).
Understanding the project requirements
The first things first, let's try to understand how the system will work, what is the basic necessities, what changes and circumstances that will require a coffee machine.
The program will work as follows: The program will show menu items and ask the user if they want a drink. The user can choose their preference.
If a user chooses a drink, we will have to make sure our coffee has enough sources to make coffee. If so, then we will go forward. Besides, we will notify the user.
If resources are sufficient, then we will ask the user to be paid in the type of coins, pens, DESES, and residential areas. We will count the payment made compared to the cost. If the payment is complete, we will make coffee and serve it. If the payment made more than price of coffee, we will give them their changes back. Besides, if the payment falls in price, we will reject the order and return their coins.
Otherwise we will add that if a person from management seeks to know the remaining resources, or money machine has kept after completing orders, can find this by typing the 'report' by typing. In addition, if managers want to turn off work completely, they can do it by typing 'to turn off'
Let's explain all this with the help of FlowChart:
Step 1: Describing menu and resources
The first step to enter the Coffee machine project to describe the menu and resources for a machine to prepare for any command. In our example, we will have 3 things in the menu: Latte, Espresso, and Cappucino.
We will use the Python dictionary to describe the menu flexibility. The Python dictionary is an effective data system that stores data against the key, both of which are easily accessible. The menu flexibility will only be a dictionary not only 3 menu, namely, latte, cappuccino, and espresso, but also describe the ingredients required to make and their price. Let's write the above code:
menu = {
"espresso": {
"ingredients": {
"water": 50,
"milk" : 0,
"coffee": 20,
},
"price": 1.5,
},
"latte": {
"ingredients": {
"water": 150,
"milk": 200,
"coffee": 25,
},
"price": 2.5,
},
"cappuccino": {
"ingredients": {
"water": 250,
"milk": 100,
"coffee": 25,
},
"price": 3.0,
}
}
The following work is to describe the resources we have. These are resources that will need to make different types of coffee, as well as the amount produced by selling coffee.
resources = {
"water": 1000,
"milk": 1000,
"coffee": 100,
"money": 0
}
As you can see, we have certain amounts of each ingredient as our resources, as well as 0 and no coffee is sold earlier.
Step 2: Ask the user in order
The next step is to ask the user what they would like to order. We will use the Python installation work for this purpose. In addition, we will change the installation cord to easily be accompanied by our subsequent situations.
order = input("What would you like to order?n Cappuccino, Latte or Espresso?n").lower()
Step 3: Apply special cases using conditions
Next, we will charge 2 special charges. The first is that if the management want to change the machine completely, they will enter off Like the above statement, the machine will extend, or in other words, the system will end. We will explain the variable of this purpose called end that will be the case False At first and you will turn True When management wants to turn off machine.
Another case will include you here is where managers would like to know the resources at a coffee machine, they will enter reportAnd the machine will print existing resources report. Let's put these cases in the code:
if order == 'off':
end = True
elif order == 'report':
print(f"We have the following resources:nWater: {resources['water']}mlnMilk: {resources['milk']}mlnCoffee: {resources['coffee']}g nMoney: ${resources['money']}")
Note to use n and F-string to formally form this report well. The result will be:

Step 4: Check Resources
The next step is to look at the resources needed to make coffee. If Espresso requires 50ML water and 20g of coffee, and any ingredients are not enough, we cannot continue to make coffee. Only when ingredients are there to continue making coffee.
This will be longer in the code, we will look into one other than each ingredients are in our resources:
if resources['water'] >= menu[order]['ingredients']['water']:
if resources['milk'] >= menu[order]['ingredients']['milk']:
if resources['coffee'] >= menu[order]['ingredients']['coffee']:
#We will prepare order
else:
print("nResources insufficient! There is not enough coffee!n")
else:
print("nResources insufficient! There is not enough milk!n")
else:
print("nResources insufficient! There is not enough water!n")
Only 3 conditions are tested, then we will continue to make coffee; Besides, print the user which ingredients are not enough. Also, we should make sure that the user has paid the amount of their order. Let's do that.
Step 5: Ask and Count Payment
According to the scenery, where all services are available, the next step is to ask the user to pay the price. When payment is completed, we will make coffee.
print(f"Pay ${menu[order]['price']}n")
Now we will ask the user to include coins (our coffee machine is expired, so thy co-operatives: p). We will ask for coins included and calculate the total amount, and match it to their order's price.

Coins installed at a coffee machine in 4 different types:
- PENDS = $ 0.01
- Nickel = $ 0.05
- Dimes = $ 0.10
- Quarter = $ 0.25
This page total The value will be calculated by multiplying the amount of currencies in their prices. Make sure to change the installation into an int; Besides, you'll be wrong.
print("Insert coins")
p = int(input("Insert pennies"))
n = int(input("Insert nickels"))
d = int(input("Insert dimes"))
q = int(input("Insert quarters"))
total = (p * 0.01) + (n * 0.05) + (d * 0.10) + (q * 0.25)
Next, to check whether total The number of accounts equal to the price of the selected coffee or not? Here's how we will be:
if total == menu[order]['price']:
print("Transaction successful. Here is your coffee!")
elif total > menu[order]['price']:
change = total - menu[order]['price']
print(f"You have inserted extra coins. Here is your change ${change}n")
else:
print("Payment not complete. Cannot process order")
Only when the amount is equal to the price of coffee, the transaction is successful. If total The amount is greater than price, we will need to restore the change to the user. Besides, if the full amount falls into price, we will cancel the order.
Step 6: Make Coffee
The last step is to move a coffee to the user, and we will do so by renewing ingredients and money in our dictionary.
if total == menu[order]['price']:
resources['water'] = resources['water'] - menu[order]['ingredients']['water']
resources['coffee'] = resources['coffee'] - menu[order]['ingredients']['coffee']
resources['milk'] = resources['milk'] - menu[order]['ingredients']['milk']
resources['money'] = resources['money'] + menu[order]['price']
print("Transaction successful. Here is your coffee!")
Note that the ingredients are issued from the resources while the money is added. Therefore, our Resources dictionary is renewed with each order that is brought. The same situation will be added when we have more money and we are required to give back changes.
Step 7: The continuation of the program
After a coffee order is processed, as long as managers do not attend the coffee machine to turn off, the machine will continue to ask the user with their own coffee order, processing payments, and placing coffee. We will therefore put the loop for a while to ensure that the program is continuing after the drink has been submitted.
The whole color block that we have above will be included in this while Loop:
while end != True:
order = input("nWhat would you like to order?nCappuccino, Latte or Espresso?n").lower()
if order == 'off':
end = True
elif order == 'report':
print(f"We have the following resources:nWater: {resources['water']}mlnMilk: {resources['milk']}mlnCoffee: {resources['coffee']}g nMoney: ${resources['money']}")
elif resources['water'] >= menu[order]['ingredients']['water']:
if resources['milk'] >= menu[order]['ingredients']['milk']:
if resources['coffee'] >= menu[order]['ingredients']['coffee']:
print(f"Pay ${menu[order]['price']}n")
# TODO : Coins insert
print("Insert coins")
p = int(input("Insert pennies"))
n = int(input("Insert nickels"))
d = int(input("Insert dimes"))
q = int(input("Insert quarters"))
total = (p * 0.01) + (n * 0.05) + (d * 0.10) + (q * 0.25)
if total == menu[order]['price']:
resources['water'] = resources['water'] - menu[order]['ingredients']['water']
resources['coffee'] = resources['coffee'] - menu[order]['ingredients']['coffee']
resources['milk'] = resources['milk'] - menu[order]['ingredients']['milk']
resources['money'] = resources['money'] + menu[order]['price']
print("Transaction successful. Here is your coffee!")
elif total > menu[order]['price']:
change = total - menu[order]['price']
print(f"You have inserted extra coins. Here is your change ${change}n")
else:
print("Payment not complete. Cannot process order")
else:
print("nResources insufficient! There is not enough coffee!n")
else:
print("nResources insufficient! There is not enough milk!n")
else:
print("nResources insufficient! There is not enough water!n")
Store
We have successfully turned the performance of coffee machine to the Python code. In time of the project, we explored the dictionaries and received ourselves, conditional statements, and the Sova. Directly, we can also simplify the project and other strategies such as targeted programs (future project). Share your feedback on the project and any suggestions on how to improve it. Until then, enjoy your coffee!

Access the complete code here:



