Python Forum
Can't stop if statement from executing even though False + Messy code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't stop if statement from executing even though False + Messy code?
#2
The way you compute sufficient_reserves is wrong. Work through the logic for an order where you don't have enough coffee, but all the other reserves are sufficient. What is the value of sufficient_reserves.

You should also rethink how you are checking the reserves. How would you modify your program to allow making smoothies? Now you have fruit used in some recipes and not in others. Can you make your reserve_check more generic so it only checks items that are in the recipe?

This kind of code is very difficult to exapand. Imagine that you made enough money from the coffee shop to open a restaurant where you have hundreds of ingredients. What would this code look like:
    if water_reserve - chosen_order_water <= 0:
        print("There isn't enough water. Please refill.")
    if milk_reserve - chosen_order_milk <= 0:
        print("There isn't enough milk. Please refill.")
    if coffee_reserve - chosen_order_coffee <= 0:
        print("There isn't enough coffee. Please refill.")
    else:
        sufficient_reserves = True
You can replace these lines of code with a loop and one comparison. The same code will work for 3 ingredients or a thousand.
monkeydesu likes this post
Reply


Messages In This Thread
RE: Can't stop if statement from executing even though False + Messy code? - by deanhystad - Oct-17-2022, 05:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  HELP - Writing code returning True or False Kokuzuma 2 2,809 Nov-01-2018, 03:37 AM
Last Post: Kokuzuma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020