#🔒 back with the coffee machine, but a new problem ;-;
72 messages · Page 1 of 1 (latest)
@slate pagoda
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
https://paste.pythondiscord.com/3H4Q
here is the code
https://paste.pythondiscord.com/227Q
this is the file with the dictionaries
!pastebin
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
the code has changed
history help - shows menu
history clear - clears ai chat history
history get <id> - gets an history item
history help - shows menu
history clear - clears ai chat history
history get <id> - gets an history item
damn ok
Hmm, there seem to be a few issues already
I noticed this last time you posted your code. You can't reassign a global dictionary from a function
wdym?
oh, i just changed it
that is the empty value i want to assign as the ingredients in "coffee" value put by user
come to think of it, i should do that first
left_ingredients = display_ingredients(MENU[coffee["ingredients"]])
well here, you're assigning left_ingredients to the result of display_ingredients()
why?
def display_ingredients(stuff):
for key, value in stuff.items():
print(f"{key} : {value}")
that function doesn't return anything
but also I'm not sure why you would want to do that anyways
i was testing something out haha
we can't decipher what was just for testing and what is meant to be your actual logic
i just wanted to check if it would display correctly
well, that out of the way
print(f"you need this and that for {coffee}")
left_ingredients = (MENU[coffee]["ingredients"])
print(left_ingredients)```
this is the new code
it just assigns the left_ingredients to the coffee ingredients
what i want is that the resources to get subtracted by the coffee ingredients once i order it
it seems this function's sole responsibility should be displaying the ingredient cost. It shouldn't do anything to your actual resources
you can create another function for that
no no
I don't know your exact requirements though
alright
let me tell you whats going on
-first of, what i wanted the function to do is display the ingredients left in our left_resources dict after the coffee ingredients dict have been assigned to it subtracted by our resources dict
@fierce sun if you don’t mind could you take a look at my question after you’re done with this
I saw your question and that's outside my expertise, sorry
Alright thanks
I don't understand what the actual use of left_resources is?
why do you need it?
i figured i needed a new variable to assign the ingredients from the "coffee" variable to then safely subtract our resources
using a loop
loop through the ingredients required for that drink choice
then access that same key in your resources and subtract that amount
you should first verify that you have all the necessary ingredients
i hate loops ðŸ˜
practice them more and you won't hate them so much
if statement in for loop?
yes, if the requirements are more than your resources, then you can return some sort of invalid message
Loops are foundational. You'll need to use them pretty regularly for anything non-trivial. You should just work to practice them so you have a better understanding of them.
so you'll want to split up your logic here
okay
first check if you have the required ingredients
i understand
return True if you do or False if you don't
if True was returned, then you can subtract your ingredients
alright
maybe see if you can work out the logic in a separate file, then try and integrate it into your main program
it makes testing quicker
yeah im doing that rn
thanks guys
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.