From the course: Programming Foundations: Data Structures
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
GitHub Codespace solution: Inventory tracker - Python Tutorial
From the course: Programming Foundations: Data Structures
GitHub Codespace solution: Inventory tracker
(upbeat music) - [Narrator] Let's walk through building an inventory tracker in Python using data structures. We'll begin by choosing a data structure to hold our inventory, and then we'll add functionality to manage its items. For this application, we'll store inventory items in a dictionary. Each item's name will be a key, and its value will be the associated quantity. This setup allows for efficient retrieval, updating, and deletion of items in the inventory. Since dictionary entries can be accessed directly using the item name. To add an item to the inventory, we'll access the dictionary and use the item_name as the key. Then we'll use the passed-in value as its quantity. Now, this works if the item is not in the inventory already, but if it already exists, we'll want to update its quantity instead. We can check if the item is in the inventory with an IF statement; if the item_name is in the inventory, we'll update its quantity instead. We'll use += quantity. This'll increment the…
Contents
-
-
-
-
-
-
-
-
-
(Locked)
GitHub Codespace challenge: To-do list1m 34s
-
(Locked)
GitHub Codespace solution: To-do list4m 20s
-
(Locked)
GitHub Codespace challenge: Reservation waitlist1m 23s
-
(Locked)
GitHub Codespace solution: Reservation waitlist2m 30s
-
(Locked)
GitHub Codespace challenge: Inventory tracker1m 27s
-
(Locked)
GitHub Codespace solution: Inventory tracker2m 44s
-
(Locked)
-
-