Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.

Refactor: Update Inventory and process_order to use numerical IDs #17

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ def unhandled_exception():
obj['keyDoesntExist']

Inventory = {
'wrench': 1,
'nails': 1,
'hammer': 1
1: 20, # Example product
2: 15, # Example product
3: 10, # Product ID 3 ('Plant Mood') with enough stock
4: 12, # Additional product
5: 18 # Additional product
}

def process_order(cart):
global Inventory
tempInventory = Inventory
for item in cart:
if Inventory[item['id']] <= 0:
raise Exception("Not enough inventory for " + item['id'])
raise Exception("Not enough inventory for " + str(item['id']))
else:
tempInventory[item['id']] -= 1
print 'Success: ' + item['id'] + ' was purchased, remaining stock is ' + str(tempInventory[item['id']])
Expand Down
Loading