Skip to content

Added Coffee Machine project to the repository #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions Coffee Machine/CoffeeMachine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
cash=0
menu={
'latte': {
'ingredients': {
'water': 200,
'milk': 150,
'coffee': 24
},
'cost':150
},

'espresso': {
'ingredients': {
'water': 50,
'coffee': 18
},
'cost': 100
},

'cappuccino': {
'ingredients': {
'water': 250,
'milk': 100,
'coffee': 24
},
'cost': 200
}
}
def collect_coins():
print("Please insert coins ")
five= int(input("How many 5 coins? "))
ten= int(input("How many 10 coins? "))
twenty= int(input("How many 20 coins? "))
sum= (five*5)+(ten*10)+(twenty*20)
return sum

def check_resources(order_ingredients):
for item in order_ingredients:
if order_ingredients[item] > resources[item]:
print(f"Sorry there is not enough {item}.")
return False
return True

def payment_process(money,drink_cost):
if money>=drink_cost:
change=money-drink_cost
print(f"Here is your change {change}.")
global cash
cash+=drink_cost
return True
else:
print("Sorry that's not enough money. Money refunded.")
return False

def make_coffee(drink_name,order_ingredients):
for item in order_ingredients:
resources[item] -= order_ingredients[item]
print(f"Here is your {drink_name} ☕. Enjoy!")

resources= {
'water': 300,
'milk': 500,
'coffee': 350
}

flag=False
while not flag:
choice=input("What would you like? (latte/espresso/cappuccino): ")
if choice=='off':
flag=True
elif choice=='report':
print(f"Water: {resources['water']}ml")
print(f"Milk: {resources['milk']}ml")
print(f"Coffee: {resources['coffee']}g")
print(f"Money: ${cash}")
else:
drink=menu[choice]
if check_resources(drink['ingredients']):
payment=collect_coins()
if payment_process(payment,drink['cost']):
make_coffee(choice,drink['ingredients'])
else:
print("Sorry, we don't have enough resources to make that drink.")
print("Thank you for using the coffee machine!")
71 changes: 71 additions & 0 deletions Coffee Machine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ☕ Coffee Machine Project

This is a simple Python project that simulates a coffee vending machine.
Users can choose from different types of coffee, insert coins to pay, and receive their drinks if enough resources and payment are available.

## Features

- Menu options: **Latte**, **Espresso**, **Cappuccino**
- Coin collection and payment processing
- Resource checking (water, milk, coffee)
- Transaction management (gives change if needed)
- Report generation for current resources and earnings
- Machine shutdown option (`off` command)

## How It Works

1. The machine asks, **"What would you like? (latte/espresso/cappuccino)"**.
2. If enough ingredients are available:
- It asks how many coins the user is inserting (5, 10, 20 coins).
- It checks if the inserted money is enough.
- If yes, it deducts ingredients, gives change if needed, and serves coffee.
- If not, it refunds the money.
3. Special Commands:
- Type `report` to see the current resources and money.
- Type `off` to turn off the machine.

## Requirements

- Python 3

(No external libraries are required.)

## How to Run

1. Save the code in a Python file, e.g., `CoffeeMachine.py`.
2. Open your terminal or command prompt.
3. Navigate to the folder containing `CoffeeMachine.py`.
4. Run the script:

```bash
python CoffeeMachine.py
```

## Example Usage

```
What would you like? (latte/espresso/cappuccino): latte
Please insert coins
How many 5 coins? 4
How many 10 coins? 5
How many 20 coins? 2
Here is your change 30.
Here is your latte ☕. Enjoy!
Thank you for using the coffee machine!
```

## Project Structure

```
CoffeeMachine.py # Main program file
README.md # Project description and instructions
```

## Future Improvements

- Add more drink options.
- Handle invalid inputs more smoothly.
- Introduce different coin denominations.
- Add an admin login to refill resources.

---