Return A Tuple Of Objects
In the Person object, there is already a support for an inventory, and when the Person object takes a Weapon object or Food object, the object would go to the inventory. For our Tr
Solution 1:
Here:
ifisinstance(item, self.RangedWeapon):
returntuple(item)
You aren't returning a tuple of all weapons, you're converting one weapon from a named tuple to a regular tuple and returning the single object. This strips the named attributes, hence the error. Instead, you need something like:
defget_weapon(self):
weapons = []
for item in self.get_inventory():
ifisinstance(item, RangedWeapon):
weapons.append(item)
returntuple(weapons)
You should also move all of the code outside get_weapon
(cc = Tribute("Chee Chin", 100)
onwards) outside the class entirely, i.e. dedent it all one more tab.
Solution 2:
Try:
defget_weapons(self):
weapons = []
for item in self.get_inventory():
ifisinstance(item, RangedWeapon):
weapons.append(item)
elifisinstance(item, Weapon):
weapons.append(item)
returntuple(weapons)
Post a Comment for "Return A Tuple Of Objects"