Created
September 3, 2021 20:38
-
-
Save elessime/ab1b1ac8160016e088bf0eb63a143316 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from data import * | |
drink_choices = {"espresso": espresso, "latte": latte, "cappuccino": cappuccino} | |
on = True | |
def resources_check(order): | |
after_service_state = {x: resources[x] - order[x] for x in resources.keys()} | |
for key, value in after_service_state.items(): | |
if value < 0: | |
print(f"Sorry not enough {key}!") | |
return True, {} | |
return False, after_service_state | |
def payment_procedure(order): | |
print("Please insert coins:") | |
total = 0 | |
for key, value in currency.items(): | |
total += value * int(input(f"Number of {key}: ")) | |
price = order["Money"] | |
rest = total - price | |
return total, price, rest | |
def vending_procedure(total, price, rest, after_service, drink_name): | |
if total >= price: | |
if rest > 0: | |
print(f"Here is your ${rest:.2f} in change") | |
after_service["Money"] = resources["Money"] + price | |
updated_resources = after_service | |
print(f"Here's Your {drink_name} ☕. Enjoy!") | |
return updated_resources | |
else: | |
print("Sorry that's not enough money. Money refunded.") | |
while on: | |
user_input = input("What would You like (espresso/latte/cappuccino):") | |
if user_input == "off": | |
on = False | |
elif user_input == "report": | |
print(f"Available resources\nWater: {resources['Water']}ml\nMilk: {resources['Milk']}ml" | |
f"\nCoffee: {resources['Coffee']}g\nMoney: ${resources['Money']}") | |
elif user_input in drink_choices.keys(): | |
drink = drink_choices[user_input] | |
is_failed_transaction, after_service = resources_check(drink) | |
if not is_failed_transaction: | |
total, price, rest = payment_procedure(drink) | |
resources = vending_procedure(total, price, rest, after_service, user_input) | |
else: | |
print("Wrong command. Try again...") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment