Question: PROBLEM 3 In this python problem, we redesign the inventory program for Trish's bookstore using dictionaries. Note: We will be continuing this redesign in Lab

PROBLEM 3
In this python problem, we redesign the inventory program for Trish's bookstore using dictionaries. Note: We will be continuing this redesign in Lab 10.
Copy the starter code Lab09P3-starter.py to a file named Lab09P3.py.
Remember in Lab 08, you used a list of lists to store the item information in the inventory system before writing it out to a file. You will change that now so that you are keeping the information in three dictionaries instead.
There are three TODO comments:
At the first TODO comment, create three empty directories named inventory_counts, inventory_costs and inventory_categories.
At the second TODO comment, update the dictionaries with the user entered data. Use the item_name as the key in all dictionaries and store the appropriate data.
o For example, if the user first entered the item name "Science Books" with an item count of 10, a unit cost of 12.95, and a category "Book" this is what the dictionaries would look like:
inventory_counts ={"Science Books": 10}
inventory_costs ={"Science Books": 12.95}
inventory_categories ={"Science Books": "Book"}
At the third TODO comment, print the dictionaries.
Same output:
Welcome to Trish's Inventory Input System
Enter the item name: Science Book
Enter the item count: 8
Enter the unit cost: 14.99
Enter the category: Book
Enter another item? (y/n) y
Enter the item name: Monopoly
Enter the item count: 10
Enter the unit cost: 17.95
Enter the category: Game
Enter another item? (y/n) y
Enter the item name: Die Hard
Enter the item count: 7
Enter the unit cost: 5.00
Enter the category: DVD
Enter another item? (y/n) n
Inventory counts: {'Science Book': 8, 'Monopoly': 10, 'Die Hard': 7}
Inventory costs: {'Science Book': 14.99, 'Monopoly': 17.95, 'Die Hard': 5.0}
Inventory categories: {'Science Book': 'Book', 'Monopoly': 'Game', 'Die Hard': 'DVD'}
Submit the program file Lab09P3.py to Blackboard for credit. Sample output:
Welcome to Trish's Inventory Input System
Enter the item name: Science Book
Enter the item count: 8
Enter the unit cost: 14.99
Enter the category: Book
Enter another item? (y/n) y
Enter the item name: Monopoly
Enter the item count: 10
Enter the unit cost: 17.95
Enter the category: Game
Enter another item? (y/n) y
Enter the item name: Die Hard
Enter the item count: 7
Enter the unit cost: 5.00
Enter the category: DVD
Enter another item? (y/n) n
Inventory counts: {'Science Book': 8, 'Monopoly': 10, 'Die Hard': 7}
Inventory costs: {'Science Book': 14.99, 'Monopoly': 17.95, 'Die Hard': 5.0}
Inventory categories: {'Science Book': 'Book', 'Monopoly': 'Game', 'Die
Hard': 'DVD'}CATEGORY_LIST =['Book','DVD', 'Game']
def main():
# TODO - Create three empty dictionaries named inventory_counts,
# inventory_costs, and inventory_categories
print("Welcome to Trish's Inventory Input System")
while True:
item_name = get_item_name()
item_count = get_item_count()
unit_cost = get_unit_cost()
category = get_category()
# TODO - Add the item data to the three dictionaries. Use the item_name
# as a key for all dictionaries.
# - Add the item_count data as a value associated with the key
# item_name in inventory_counts.
# - Add the unit_cost data as a value associated with the key
# item_name in inventory_costs.
# - Add the category data as a value associated with the key
# item_name in inventory_categories.
answer =''
while answer !='y' and answer !='n':
answer = input('Enter another item? (y/n)')
answer = answer.lower()
if answer !='y' and answer !='n':
print('Enter y or n to continue.')
if answer =='n':
break
# TODO - Print the three dictionaries as shown in assignment's
# sample output.
def get_item_name():
# Get item name
item_name = input('Enter the item name: ')
return item_name
def get_item_count():
# Get item count
while True:
try:
item_count = int(input('Enter the item count: '))
if item_count 0:
print('Item count must be 0 or greater.')
else:
break
except:
print('Item count must be an integer.')
return item_count
def get_unit_cost():
# Get unit cost
while True:
try:
unit_cost = float(input('Enter the unit cost: '))
if unit_cost 0:
print('Unit cost must be 0 or greater.')
else:
break
except:
print('Unit cost can only contain digits and a single decimal point.')
return unit_cost
def get_category():
while True:
category = input('Enter the category: ')
if category not in CATEGORY_LIST:
print(f'Category must be in this list: {CATEGORY_LIST}')
else:
break
return category
main()
 PROBLEM 3 In this python problem, we redesign the inventory program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!