8000 My Coffee machineProject · kavya-git3/intro-to-python@9322a72 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 9322a72

Browse files
author
Replit user
committed
My Coffee machineProject
1 parent 052eead commit 9322a72

File tree

3 files changed

+125
-87
lines changed

3 files changed

+125
-87
lines changed

CoffeeMachine-readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Coffee Machine Project
2+
3+
Welcome to the Coffee Machine Project! This Python program simulates a coffee machine where users can select from a menu of coffee options, check available resources, and make payments to receive their chosen coffee.
4+
5+
6+
We have used the below functions in the project.
7+
8+
check_resources(order_ingredients): This function checks if there are enough resources (water, milk, coffee) available to make the selected coffee.
9+
10+
process_coins(): This function handles the payment process. It asks the user to input the number of 5rs, 10rs, and 20rs coins they want to use for payment. It calculates the total payment amount based on the number of coins and returns the total.
11+
12+
is_payment_successful(money_received, coffee_cost): This function checks if the payment received from the user is sufficient to cover the cost of the selected coffee.
13+
14+
make_coffee(coffee_name, coffee_ingredients): This function prepares the selected coffee by deducting the required ingredients from the available resources.
15+
16+
display_menu_and_date(): This function displays the current date and the coffee menu to the user.
17+
18+
19+
20+
21+
22+
23+

CoffeeMachine.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import datetime
2+
Menu = {
3+
"latte": {
4+
"ingredients": {
5+
"water": 200,
6+
"milk": 150,
7+
"coffee": 24,
8+
},
9+
"cost": 100,
10+
},
11+
"espresso": {
12+
"ingredients": {
13+
"water": 50,
14+
"coffee": 18,
15+
},
16+
"cost": 75,
17+
},
18+
"cappuccino": {
19+
"ingredients": {
20+
"water": 250,
21+
"milk": 100,
22+
"coffee": 24,
23+
},
24+
"cost": 100,
25+
},
26+
}
27+
28+
profit = 0
29+
resources = {
30+
"water": 1000,
31+
"milk": 500,
32+
"coffee": 100,
33+
}
34+
35+
36+
def check_resources(order_ingredients):
37+
for item in order_ingredients:
38+
if order_ingredients[item] > resources[item]:
39+
print(f"Sorry there is not enough {item}")
40+
return False
41+
return True
42+
43+
44+
def process_coins():
45+
print("Please insert coins.")
46+
total = 0
47+
coins_five = int(input("How many 5rs coin?:"))
48+
coins_Ten = int(input("How many 10rs coin?:"))
49+
coins_Twenty = int(input("How many 20rs coin?:"))
50+
total = coins_five * 5 + coins_Ten * 10 + coins_Twenty * 20
51+
return total
52+
53+
54+
def is_payment_successful(money_received, coffee_cost):
55+
if money_received >= coffee_cost:
56+
global profit
57+
profit += coffee_cost
58+
change = money_received - coffee_cost
59+
print(f"Here is your Rs{change} in change.")
60+
return True
61+
else:
62+
print("Sorry that's not enough money. Money refunded.")
63+
return False
64+
65+
66+
def make_coffee(coffee_name, coffee_ingredients):
67+
for item in coffee_ingredients:
68+
resources[item] -= coffee_ingredients[item]
69+
print(f"Here is your {coffee_name} ....Enjoy!!")
70+
71+
def display_menu_and_date():
72+
current_date = datetime.date.today()
73+
print(f"Welcome to the Coffee Machine!")
74+
print(f"Today's Date: {current_date}")
75+
print("\nMenu:")
76+
for coffee in Menu:
77+
cost = Menu[coffee]["cost"]
78+
print(f"{coffee.capitalize()} - Rs{cost}")
79+
print("\nType 'report' to see resource status.")
80+
print("Type 'off' to turn off the machine.")
81+
82+
83+
is_on = True
84+
while is_on:
85+
display_menu_and_date()
86+
choice = input(
87+
"What would you like to have? (latte/espresso/cappuccino): ")
88+
if choice == "off":
89+
is_on = False
90+
elif choice == "report":
91+
print(f"Water: {resources['water']}ml")
92+
print(f"Milk: {resources['milk']}ml")
93+
print(f"Coffee: {resources['coffee']}g")
94+
print(f"Money: Rs {profit}")
95+
else:
96+
coffee_type = Menu[
97+
choice] # Retrieve the selected coffee type from the menu
98+
print(coffee_type)
99+
if check_resources(coffee_type['ingredients']):
100+
payment = process_coins()
101+
if is_payment_successful(payment, coffee_type['cost']):
102+
make_coffee(choice, coffee_type['ingredients'])

main.py

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0