Skip to main content

Create the Store

We're going to start off by creating the Store class that'll manage our store.

class Store:

def __init__(name: str) -> None:
self.name = name

As we're new to running a store, we're going to keep it really simple for now. Let's imagine our store can only sell one type of product. So we only have one inventory number to keep track of. Let's add that to our Store class.

class Store:

def __init__(name: str, inventory: int) -> None:
self.name = name
self.inventory = 0

Let's create a sample store to play around with.

store = Store(
name="Awesome Store",
inventory=100
)

If we wanted to sell an item, we could simply decrease the inventory by the number of items sold. Similarly if we receive a new shipment, we can increase the inventory.

# Sold 3 items
store.inventory -= 3
print(store.inventory) # Output: 97

# Received a shipment of 10 new items
store.inventory += 10
print(store.inventory) # Output: 107

And there you have it! A simple store class to manage inventory.