Skip to content

Created coffee_machine.py #379

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: main
Choose a base branch
from
Open
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
132 changes: 132 additions & 0 deletions Python/coffee_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
MENU = {
"espresso": {
"ingredients": {
"water": 50,
"coffee": 18,
},
"cost": 1.5,
},
"latte": {
"ingredients": {
"water": 200,
"milk": 150,
"coffee": 24,
},
"cost": 2.5,
},
"cappuccino": {
"ingredients": {
"water": 250,
"milk": 100,
"coffee": 24,
},
"cost": 3.0,
}
}
profit = 0
resources = {
"water": 300,
"milk": 200,
"coffee": 100,
}
end_of_task=True
while end_of_task:
def update_resources(cofee):
if (cofee == 'espresso'):
resources["water"]-=50
resources["coffee"]-=18
elif (cofee == 'latte'):
resources["water"]-=200
resources["milk"]-=150
resources["coffee"]-=24
elif (cofee == 'cappuccino'):
resources["water"]-=250
resources["milk"]-=100
resources["coffee"]-=24

def check_resources(cofee):
if cofee == 'espresso':
if resources["water"]<50:
print("Insufficient water")
return 0
elif resources["coffee"]<18:
print("Insufficient coffee")
return 0
elif cofee == 'latte':
if resources['water']<200:
print("Insufficient water")
return 0
elif resources["milk"]<150:
print("Insufficient milk")
return 0
elif resources["coffee"]<24:
print("Insufficient coffee")
return 0
elif cofee == 'cappuccino':
if resources["water"]<250:
print("Insufficient water")
return 0
elif resources["milk"]<100:
print("Insufficient milk")
return 0
elif resources["coffee"]<24:
print("Insufficient coffee")
return 0
def report():
for key in resources:
print(f"{key}: {resources[key]}ml")
print(f"Money: ${profit}")
choice=input("What would you like? (espresso/latte/cappuccino): ")
coffee(choice)

def coin():
print("please insert coins.")
quarter=int(input("how many quarters?: "))
dimes=int(input("how many dimes?: "))
nickles=int(input("how many nickles?: "))
pennies=int(input("how many pennies?: "))
coin=0.25*quarter+0.10*dimes+0.05*nickles+0.01*pennies
return coin

def coffee(choice):
global profit
# choice=input("What would you like? (espresso/latte/cappuccino): ")
if choice == 'report':
report()
else :
if (choice == 'espresso'):
check=check_resources(choice)
if check == 0:
end_of_task=False
if check!=0:
value=coin()
change=round(value-1.5,2)
profit+=1.5
print(f"Here is ${change} in change")
print("Here is your espresso. Enjoy!")
update_resources(choice)
elif (choice == 'latte'):
check=check_resources(choice)
if check == 0:
end_of_task=False
if check!=0:
value=coin()
change=round(value-2.5,2)
profit+=2.5
print(f"Here is ${change} in change")
print("Here is your latte. Enjoy!")
update_resources(choice)
elif (choice == 'cappuccino'):
check=check_resources(choice)
if check == 0:
end_of_task=False
if check!=0:
value=coin()
change=round(value-3.0,2)
profit+=3.0
print(f"Here is ${change} in change")
print("Here is your cappuccino. Enjoy!")
update_resources(choice)

choose=input("What would you like? (espresso/latte/cappuccino): ")
coffee(choose)