Modified code from yesterday.
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,}}resources = {"water": 300,"milk": 200,"coffee": 100,"money": 0,}coffee_price = 0quarters = 0dimes = 0nickels = 0pennies = 0water_needed = 0milk_needed = 0coffee_needed = 0def report():"""outputs a present state report of the coffee machine"""print(f"Water: {resources["water"]}")print(f"Milk: {resources["milk"]}")print(f"Coffee: {resources["coffee"]}")print(f"Money: {resources["money"]}")def resource_sufficient(water_needed, milk_needed, coffee_needed):if choice == "espresso":if water_needed < resources["water"]:print("Sorry, there is not enough water.")elif coffee_needed < resources["coffee"]:print("Sorry, there is not enough coffee.")elif choice == "latte":if water_needed < resources["water"]:print("Sorry, there is not enough water.")elif milk_needed < resources["milk"]:print("Sorry, there is not enough milk.")elif coffee_needed < resources["coffee"]:print("Sorry, there is not enough coffee.")elif choice == "cappuccino":if water_needed < resources["water"]:print("Sorry, there is not enough water.")elif milk_needed < resources["milk"]:print("Sorry, there is not enough milk.")elif coffee_needed < resources["coffee"]:print("Sorry, there is not enough coffee.")while True:choice = input("What would you like? (espresso/latte/cappuccino): ")if choice == "espresso":water_needed = MENU["espresso"]["ingredients"]["water"]milk_needed = 0coffee_needed = MENU["espresso"]["ingredients"]["coffee"]coffee_price = MENU["espresso"]["cost"]elif choice == "latte":water_needed = MENU["latte"]["ingredients"]["water"]milk_needed = MENU["latte"]["ingredients"]["milk"]coffee_needed = MENU["latte"]["ingredients"]["coffee"]coffee_price = MENU["latte"]["cost"]elif choice == "cappuccino":water_needed = MENU["cappuccino"]["ingredients"]["water"]milk_needed = MENU["cappuccino"]["ingredients"]["milk"]coffee_needed = MENU["cappuccino"]["ingredients"]["coffee"]coffee_price = MENU["cappuccino"]["cost"]elif choice == "off":breakelif choice == "report":report()breakelse:print("Sorry, that's not a valid input. Please try again.")breakprint("Please insert coins.")quarters = float(input("how many quarters?: "))dimes = float(input("how many dimes?: "))nickels = float(input("how many nickels?: "))pennies = float(input("how many pennies?: "))total_quarters = 0.25 * quarterstotal_dimes = 0.10 * dimestotal_nickels = 0.05 * nickelstotal_pennies = 0.01 * penniestotal_amount_inserted = total_quarters + total_dimes + total_nickels + total_pennies
resource_sufficient(water_needed, milk_needed, coffee_needed)if total_amount_inserted < coffee_price:print("Sorry that's not enough money. Money refunded.")breakelse:change = total_amount_inserted - coffee_priceprint(f"Here is ${change:.2f} dollars in change.")print(f"Here is your {choice}. Enjoy!")resources["water"] = resources["water"] - water_neededresources["milk"] = resources["milk"] - milk_neededresources["coffee"] = resources["coffee"] - coffee_neededresources["money"] = resources["money"] + coffee_price
I decided to take away as much functions as I could and did it my way. It worked but I have to strengthen my understanding of functions. :)
I also do not like that I have to call every number holding variable at the top of my code.
At first logging in made sure I did not skip a day but now it is feeling more like a chore. It gets better though.
I can do it!! :)
Comments
Post a Comment