I'm trying to pass a dictionary selection into a class function to do further things with. When I try though, I get an error saying I'm missing a parameter. I know I don't need to include self, so I'm confused as to why it isn't working. It should do:
- Receives choiceindex from other part of code taking user input
- Uses the choiceIndex to select from the dictionary
- Pass in the 3 pieces of the dictionary to the Product class
Project is to simulate a Coffee Machine. Quoted out are a few of the things I've tried but don't work. Any help or advice is much appreciated
class Product(object):
def __init__(self,name,price,recipe):
self.name = name
self.price = price
self.recipe = recipe
def getPrice(self):
return self.price
def make(self, name, price, recipe):
print(self.recipe)
#for item in recipe:
# print("dispensing", item)
class Selector(object):
def __init__(self):
#self.Product = Product()
self.cashBox = CashBox
self.product = []
#self.products.append(Product.
def select(self, choiceIndex):
recipes = {
1 : ["black","35","cup coffee water"],
#1 : ["black",35,"cup coffee water"],
#1 : self.Product.make("black",35,"cup coffee water"),
2 : ["white",35,["cup", "coffee", "creamer", "water"]],
3 : ["sweet",35,["cup", "coffee", "sugar", "water"]],
4 : ["white&sweet",35,["cup", "coffee", "sugar", "creamer", "water"]],
5 : ["bouillon",35,["cup bouillonPowder", "water"]]
}
if choiceIndex in range(1,len(recipes)+1):
self.choiceIndex = choiceIndex
self.recipe = recipes.get(choiceIndex)
print(self.recipe,"Great selection")
Product.make(*self.recipe)
else:
print("That selection does not exist")
Error occurred:
Exception has occurred: TypeError
make() missing 1 required positional argument: 'recipe'
File "C:\Users\Tanner Harmer\Desktop\Coffee2\CashBox.py", line 101, in select
Product.make(*self.recipe)
File "C:\Users\Tanner Harmer\Desktop\Coffee2\CashBox.py", line 41, in oneAction
Selector.select(self,int(words[1]))
File "C:\Users\Tanner Harmer\Desktop\Coffee2\CashBox.py", line 107, in main
while m.oneAction():
File "C:\Users\Tanner Harmer\Desktop\Coffee2\CashBox.py", line 113, in <module>
main()