Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For Python 3.7+. 1. read a set of inventory items from a text file (LA1) 2. create a Python list for each item (LA1) 3.

For Python 3.7+.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

1. read a set of inventory items from a text file (LA1) 2. create a Python list for each item (LA1) 3. display each item in the list (LA1) 4. build a reverse dictionary consisting of each item type as key and all items in that category as the value (A1) 5. create an output file and write each item to it by iterating through the dictionary and writing by category+item (A1) Input File You will be provided with an input file consisting of inventory items. The file name is Alinput.txt. Each line consists of comma-separated data: inventory number, category, description, and price. Part of the input file is shown below. The actual file has additional lines. Note that the inventory number has 4 characters, the category is in the set {"book, elect, cloth, and food"}. The description is free text, up to 25 characters in length. The price is floating point with only two digits to the right of the decimal. B001,book,Patriot Games, 15.95 B002, book, Origin, 19.95 C001,cloth, Armani Suit, 800.00 B003,book, Animal Farm, 9.97 B004,book,Grant, 22.50 E001,elect,EyePhone 10,795.00 E002,elect,First Alert Smoke Alarm, 29.95 F001, food, Moose Drool Ale 6-pack, 9.95 C002,cloth,Pants, 39.95 B005,book,Prairie Fires, 18.95 E003,elect Sony Portable Radio, 15.00 C003,cloth, Vasque Hiking Boots, 109.00 C004,cloth, Wool Hat, 14.00 F002, food,Jumbo shrimp, 12.50 E004,elect, HP Laptop, 350.00 Functions The separate functions to be implemented should be such that the global code is minimized. With most of the program's action being handled by the functions the global code could be approximately this small: itemList = loadItems() #invoke function to read the file into a list, return the list displayItems(itemList) #takes list as input and prints it (this should be simple) print(" ') #inserts some separating spaces DS = buildDict(itemList) #builds and returns the "reverse" dictionary from the input list writeFile(DS) # creates output file and writes records to it Reverse Dictionary The 'buildDict() function reads each inventory item from the input list and takes one of the following actions: 1. if the "category of the item read is not already in the dictionary, that category is added as a key and the inventory number, description, and price are made into a list and inserted as a value of that category's key 2. if the "category of the item read is already in the dictionary, the inventory number, description, and price are made into a list and appended to that key's value. The resulting dictionary has as many entries as categories. Each entry is a list of lists. The master list includes everything for the corresponding category, while each sub-list is the data for one particular inventory item. An example of the dictionary for the 'book'category: {book: [[*B001', 'Patriot Games', 15.95], [*B002', 'Origin?, 19.95], ... [*B006', 'Future Shock, 8.95]]} Output File The output file is a text file consisting of comma-separated data. The file name you create is Aloutput.txt" (example: "smithfAloutput.txt"), written to your default drive and directory. There is one line per data item. Each line consists of (1) category, (2) inventory number, (3) description, and (4) price. The reverse dictionary will supply these to your function. Iterating through the reverse dictionary will yield lines like the ones below. When writing to the file write out the dictionary key followed by inventory number, description, and price (brackets '[' and 'J' will not be written to the output file). The output is a set of comma-separated text strings. book,B001,Patriot Games, 15.95 book,B002,Origin, 19.95 book,B003, Animal Farm, 9.97 book,B004, Grant, 22.50 book,B005,Prairie Fires, 18.95 book, B005, Ragtime, 17.25 book,B006,Future Shock, 8.95 cloth, C001,Armani Suit, 800.00 cloth, C002,Pants, 39.95 cloth, C003, Vasque Hiking Boots, 109.00 cloth, C004,Wool Hat, 14.00 cloth,C005,Wrangler Jeans, 24.50 cloth,C006,Nike T-shirt, 19.00 cloth, C007,Gore-Tex Gloves, 39.00 cloth, C008, North Face Fleece Jacket, 89.95 cloth, C009, Nationals Logo Sweatshirt, 49.00 cloth,C010,New Balance Trail Runners', 69.95 elect,E001,EyePhone 10, 795.00 elect,E002,First Alert Smoke Alarm, 29.95

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

10.5 Some Comments on Hypothesis Testing

Answered: 1 week ago