Last active
November 7, 2022 09:35
-
-
Save wanieldilson/c7bb2729c2ab9767555d2c2c742fd146 to your computer and use it in GitHub Desktop.
Coffee Machine 100 days of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
MENU = { | |
"espresso": { | |
"ingredients": { | |
"water": 50, | |
"milk": 0, | |
"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, | |
} | |
} | |
resources = { | |
"water": 300, | |
"milk": 200, | |
"coffee": 100, | |
"money": 0 | |
} | |
profit = 0 | |
user_response = "" | |
def process_coins(price): | |
all_coins = float(input("Number of quarters: ")) * 0.25 | |
all_coins += float(input("Number of dimes: ")) * 0.10 | |
all_coins += float(input("Number of nickels: ")) * 0.05 | |
all_coins += float(input("Number of pennies: ")) * 0.01 | |
change = all_coins - price | |
if all_coins == price: | |
print("Thanks for exact change") | |
return True | |
elif all_coins > price: | |
print(f"Here's your change, ${round(change, 2)}") | |
return True | |
else: | |
return False | |
def check_resources_take_money(selection): | |
water_check = MENU[selection]["ingredients"]["water"] <= resources["water"] | |
coffee_check = MENU[selection]["ingredients"]["coffee"] <= resources["coffee"] | |
milk_check = MENU[selection]["ingredients"]["milk"] <= resources["milk"] | |
price = MENU[selection]["cost"] | |
if water_check and coffee_check and milk_check: | |
print(f"Insert coins to the value of ${price}") | |
if process_coins(price): | |
make_a_coffee(selection) | |
resources["money"] += price | |
else: | |
print("Not enough cash!") | |
else: | |
print("Not enough resources!") | |
def make_a_coffee(selection): | |
resources["water"] = resources["water"] - MENU[selection]["ingredients"]["water"] | |
resources["coffee"] = resources["coffee"] - MENU[selection]["ingredients"]["coffee"] | |
resources["milk"] = resources["milk"] - MENU[selection]["ingredients"]["milk"] | |
print("Dispensing...") | |
time.sleep(3) | |
print("Enjoy your", selection) | |
def resources_report(): | |
print(f"Water: {resources['water']}ml") | |
print(f"Milk: {resources['milk']}ml") | |
print(f"Coffee: {resources['coffee']}g") | |
print(f"Money: ${resources['money']}") | |
def refill_machine(): | |
print(f"Machine restocking, collecting profit of ${resources['money']}") | |
resources["water"] = 300 | |
resources["milk"] = 200 | |
resources["coffee"] = 100 | |
resources["money"] = 0 | |
while True: | |
user_response = input("What would you like? (Espresso/Capuccino/Latte): ") | |
user_response = user_response.lower() | |
if user_response == "report": | |
resources_report() | |
elif user_response == "refill": | |
refill_machine() | |
elif user_response == "off": | |
print("Powering down...") | |
quit() | |
elif user_response not in MENU.keys(): | |
print("Not on the menu MF!") | |
else: | |
check_resources_take_money(user_response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Poo & Wee