Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For Python 3.7+. Create 2 functions. The first function will read a set of inventory items for a text file and create a Python list

For Python 3.7+.

Create 2 functions. The first function will read a set of inventory items for a text file and create a Python list for each item. The second function will display each item in the list.

The separate functions to be implemented should be such that the global code is minimized. With most of the programs 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)

The file name is A1input.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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions