how do i subtract items from my inventory and print them later in my program?

you must declare that inhand function scope variable first as well making the function accessible throughout the class, then assign inventory to your class variable otherwise it wont get stored globally in your class (only inside of your function) for example:

def inhand(self,item_type,qty_purchased):
    self.inventory = { "Pants":100, "Shirt":100, "Dress":100, "Socks":100, "Sweater":100 }
    self.inventory[item_type] -= qty_purchased

so then you can use it repetitively using for loop

self.item_type_qty[["Pants",20],["Dress",20]] #for example, this variable store user picked item
for x in self.item_type_qty:
    self.inhand(x[0],x[1]) #calling inhand function repetitively

you will also need to validate if in case those inventory get valued below zero. which at this point you can figure it out on your own. good luck

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top