#πŸ”’ How do I organize my Resource class into my Drink Machine class?

25 messages Β· Page 1 of 1 (latest)

raven dock
#

Full code here: https://paste.pythondiscord.com/R45A

Specifically, I have a Resource class and I'm trying to figure out how to have the Drink Machine class hold these resources, so that I can deduct which resource each item consumes when dispensing. pithink

fickle matrixBOT
#

@raven dock

Python help channel opened

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.

warped thicket
wraith mortar
#

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

raven dock
raven dock
raven dock
wraith mortar
#

if you want to change the data structure, sure, you could make it a dict as well

raven dock
#

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

wraith mortar
#

you could have that auto-setup inside the drink machine class, sure

raven dock
#

ah... right. Make a new method that "deposits" resources into the machine.

#

OK yeah that makes sense

wraith mortar
#
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

raven dock
#

ooh

#

Yeah I should have thought of that. Thanks @wraith mortar

wraith mortar
#

np!

raven dock
#

!close

fickle matrixBOT
#
Python help channel closed

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.