I am trying to make an inventory system where obtaining an item you already have just increases the item's amount rather than adding a whole new one to the list.
def enc1():
print("hello")
def enc2():
print("hi")
def enc3():
print("howdy")
def enc4():
print("hey")
def enc5():
print("heyo")
class item:
def __init__(self, name, amount):
self.name = name
self.amount = amount
items = []
apple = item("apple", 1)
def addItem(itemToAdd):
for x in items:
if(x == itemToAdd):
itemToAdd.self.amount += 1
else:
items.append(itemToAdd)
addItem(apple)
print(items, apple.amount)
addItem(apple)
print(items, apple.amount)
encounter = random.randint(1,5)
if(encounter == 1):
enc1()
elif(encounter == 2):
enc2()
elif(encounter == 3):
enc3()
elif(encounter == 4):
enc4()
elif(encounter == 5):
enc5()