Help with oop

DL Neil PythonList at DancesWithMice.info
Sun Feb 23 17:22:27 EST 2020


On 24/02/20 10:45 AM, S Y wrote:
> """ The class Baggage will track inventory items added to or removed 
> from it. Inventory items will be represented by
> inventory item objects created using the ‘InventoryItem’ class. When an 
> attempt is made to add an inventory
> item to a Baggage object, the number of items in the Baggage object is 
> compared with maximum capacity and
> allowable items. If space is left and the item is allowed, the item is 
> added, otherwise, the class returns a response indicating failure with a 
> short reason why"""
> class Baggage:
>   #Constructor - sets initial values for all object attributes.
>   def __init__(self,capacity, inventory= [],allow_items=()):
>   self.inventory = []
>   self.capacity = 5
>   self.allow_items = (
...

>   #Adds an item object to the Baggage object after checking that the mx 
> capacity has not been reached (i.e. 5 items)
>   def add_item(self, item_object):
>   if len(self.inventory) <= self.capacity:
>   self.inventory.append(item_object)
>   return True
>   else:
>   print("Reached max capacity")
>   return False

> <python-list-bounces+saliyusufm=outlook.com at python.org> on behalf of DL 
> Neil via Python-list <python-list at python.org>
> *Sent:* Sunday, February 23, 2020 4:41:54 PM
> *To:* python-list at python.org <python-list at python.org>
> *Subject:* Re: Help with oop
> On 22/02/20 10:45 PM, S Y wrote:
>> How can I use remove,add and verify methods in class oop. Which has tuple with allowed values inside class. Like two classes cart and inventory
> 
> Please show the code you have so-far.
> What are you removing, adding, and verifying?
> Are you aware of the Python-Tutor Discussion List?

Given that the data-structure is a list, perhaps list.remove()?
What is the relevance of Baggage.allow_items()?

Sorry to be nagging you but perhaps take a look at how Discussion Lists 
work:
- top/bottom posting, ie not answer then question,
- replying to list (not individual) so that others may also benefit,
- formatting and readability (cf 'Microsoft makes it look nice because 
they know better than you')

WebRef:
5. Data Structures¶
https://docs.python.org/3/tutorial/datastructures.html
-- 
Regards =dn


More information about the Python-list mailing list