I'm trying to piece together a small assignment in Python OOP, but I'm not sure where I'm wrong.
I have two classes: Shoe and Store. In the Shoe class I just create the Shoe, and that Store class is where I'm doing all the methods.
I'm trying to create an "add shoe" method that will check if the shoe exists in a given list, if not, it will add it. I'm checking if the shoe exists by comparing the shoeID
object.
Here is my code:
class Shoe(object):
def __init__(self, shoeID, shoePrice, shoeSize, quantity):
self.shoeID = shoeID
self.shoePrice = shoePrice
self.shoeSize = shoeSize
self.quantity = quantity
def __str__(self):
return "Shoe ID:", self.shoeID, "Shoe Price:", str(self.shoePrice), "Shoe Size:", str(self.shoeSize), "Quantity:", str(self.quantity)
class Store(object):
def __init__(self):
self.shoeList = []
def __str__(self):
return "Shoe list: " + self.shoeList
def add_shoe(self, newShoe):
for i in self.shoeList:
if i.shoeID == newShoe.shoeID:
print("Shoe already exists, updating quantity")
i.quantity += newShoe.quantity
else:
print("This is a new shoe, adding it to the list")
self.shoeList.append(i)
return
This is my tester:
import shoes
testStore = shoes.Store()
shoe1 = shoes.Shoe(123, 100, 40, 2)
print(testStore.add_shoe(shoe1))
My output is always None
. I tried changing a bunch of stuff but I guess I'm just missing something stupid that I don't see.
I'd love to get some help.
Thanks!