#π How do I organize my Resource class into my Drink Machine class?
25 messages Β· Page 1 of 1 (latest)
@raven dock
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.
Is there any problem with that ?
you would have to iterate the list of resources looking for the name of the resource you want to subtract from
then you can call your consume method
also 1 space indent is so cursed
I blame the new pastebin for that 
list as in, [] and not {}? I was kinda hoping to just refer to keys but resources = {"water": water_resource} seems redundant, no?
@warped thicket That's the problem βοΈ
if you want to change the data structure, sure, you could make it a dict as well
There's no way to just grab the Resource name as the key and then value of the Resource class in a dictionary for resources?
Maybe I'm overcomplicating this
you could have that auto-setup inside the drink machine class, sure
what do you mean?
ah... right. Make a new method that "deposits" resources into the machine.
OK yeah that makes sense
class DrinkMachine:
def __init__(self, items, resources):
self.items = items
self.resources = {}
for resource in resources:
self.resources[resource.resource_type] = resource
yeah exactly, something like this
but breaking this out into a separate method would be a great idea too
np!
!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.
