1

This is my code, I have the main which creates the objects. I also have two functions one to add more items, and the second to remove items. I was able to get the add function to work properly, but I am having difficulty removing the whole object. Most things I find online are if the object has only one parameter. However, in my instance it has multiple parameters. I would appreciate any and all help!

#class for itmes
class item:

    #the init method or constructor
    def __init__(self, name, quantity, inv_date):

        #instance variable
        self.name       = name
        self.quantity   = quantity
        self.inv_date   = inv_date

#creating list of items
list = []

#objects of item class
list.append( item('hammer', 8, 123212))
list.append( item('screwdriver', 12, 42312))
list.append( item('ladder', 5, 20675))
list.append( item('paintbrush', 15, 134864))
list.append( item('nails', 64, 96245))
list.append( item('wrench', 75, 86376))
list.append( item('crowbar', 84, 127396))
list.append( item('measuring_tape', 26, 68632))
list.append( item('pliers', 85, 105208))
#list.append( item('level', 64, 95053))

#printing the list
for obj in list:
    print( obj.name, obj.quantity, obj.inv_date)


/////////////////////////////////////
/////////////////////////////////////
//////THIS IS THE ADD/REMOVE FUNCTIONS
//////////////////////////////////////
///////////////////////////////////////

#printing the list
for obj in list:
    print( obj.name, obj.quantity, obj.inv_date)

print()

def add_Item():
    name = input("Please enter the item name: \n")
    print(f'You entered {name}')
    number = input("Please enter the number of items: \n")
    print(f'You entered {number}')
    date = input("Please enter the item date: \n")
    print(f'You entered {date}')
    list.append( item(name, number, date))

def remove_Item():
    print("The numbers increase by 1, with the first item being 0")
    remove = input("Please enter number of the item to be removed: \n")
    print(f'You entered {remove}')
    list.remove( item(remove))


#add_Item()
remove_Item()

#printing the list
for obj in list:
    print( obj.name, obj.quantity, obj.inv_date)

0 Answers0