Question
Assignment Specifications Problem: Data Processing The owners of a corner store do an inventory of what items they have on their shelves after they close
Assignment Specifications
Problem: Data Processing
The owners of a corner store do an inventory of what items they have on their shelves after they close their store every day. They have asked you to create a Python program that uses this inventory information to generate a daily report of what needs to be ordered from their suppliers. The store owners will order more of a particular product when there are less than 20 of those items left on their shelves. When they order a product, they order enough to stock a total of 50 of those items on their shelves. For example, if they have 18 bags of Salt & Vinegar chips at the end of the day, they order 50-18 = 32 new bags. They may have many suppliers that offer the same product, so they must choose the supplier that offers the product at the lowest price. If all suppliers offer the product at the same price, any supplier can be selected.
Your Python program will use input data from the following four files:
The first file,products.txt,contains the list of all products sold in the store. Each line contains information about a single product: the product code, followed by a semicolon (;), followed by the product name. For example, the contents of this file could be this:
123456789;2L 2% Vitali Milk 123456798;1L 2% Vitali Milk 456392452;70% Cocoa Zimbra Chocolate 456123490;Zimbra Milk Chocolate 634590221;Onion flavour chips 634599011;Vinegar flavour chips 780123678;Sliced white bread 780432109;Sliced whole wheat bread 809001234;2L Orange Juice 808765432;2L Apple Juice
The second file,suppliers.txt,contains information about the suppliers. Each line contains the phone number, the supplier name, and the supplier's address, all separated by ";. The phone number is unique and can be used as an ID. For example, the contents of this file could be this:
7808907654;Wholesale club;56 Stony Place 7801234567;Costcorner;36 Spruce Street 7807890123;PriceCo;98 Alberta Avenue 7804922860;Lows Lili;66 Hinton Road 7809876543;Coast to coast;34 Sherwood park Avenue 7801236789;Always Supplies;101 Edson Crest 7804321098;O and Z company;32 Alphonse Street
The third file,availability.txt,contains information about what product the suppliers have and at what price. Each line contains a product code, a supplier's phone number, and the price. These 3 fields are separated by a ",. Notice that the same product may be available from multiple suppliers, but at different prices. Here is an example:
123456789,7807890123,2.58 123456789,7804922860,2.99
The last file,onshelves.txt,contains the inventory for that day. Its structure is simple. Each line has a product code followed by the number of items left on the shelves, where the two fields are separated by "#. For example:
123456789#3 123456798#9 456392452#23 456123490#14 634590221#18 634599011#15 780123678#1 780432109#5 809001234#48 808765432#28
For all four input files, you can assume that there will not be whitespace at the beginning of each line, nor will there be blank lines in the file. You can also assume that all products stocked by the store are present in availability.txt, but availability.txt may contain items that are not stocked by the store.
Your Python program must generate a file,orders.txt, that contains a table listing all of the products that must be ordered from the suppliers. The table should be formatted as follows, with the products grouped by supplier. In other words, the table should be sorted by the supplier column, with the phone numbers listed in ascending order. No additional sorting needs to be performed on the table. The supplier with the highest cumulative cost for the current order should be printed below the table, as shown. If there is a tie for the highest cumulative cost, all of those suppliers should be displayed.
+--------------+------------------+--------+----------------+----------+ | Product code | Product Name |Quantity| Supplier | Cost | +--------------+------------------+--------+----------------+----------+ | 123456789 |*2L 2% Vitali Mil | 47 | (780) 789 0123 | $ 121.26 | | 456123490 | Zimbra Milk Choc | 36 | (780) 789 0123 | $ 26.49 | ... | 780432109 |*Sliced whole whe | 45 | (780) 998 9334 | $ 89.10 | +--------------+------------------+--------+----------------+----------+ | Total Cost | $ 7292.32| +--------------+---------------------------+ Highest cost: Costcorner (780) 123 4567 [$234.05] Highest cost: O and Z company (780) 432 1098 [$234.05]
The table has 5 columns:
The first column is the product code.
The second column is the product name truncated after the 16th character. So the column has to be 18 characters wide. That is, If the product name is longer than 16 characters, the name is truncated to fit. In addition, the name is prefixed with "*" if the number to order is higher than 40.
The third column is the number of items to order. This amount is never more than 50, but the column is 8 characters wide. Align the numbers to the right of the column, but leave a single space after the number.
The fourth column is the supplier phone number. This number has to be formatted as (999) 999 9999.
The last column is the cost. This is the number of items to order multiplied by the price per item charged by the supplier. The cost should be preceded by "$". It is assumed this cost will never reach $10000 and thus should be 4 positions before the decimal point and two positions after the decimal point.
Finally, a line at the end of the table should indicate the total amount that the whole order will cost, with room for 7 digits before and 2 digits after the decimal point. The table should be formatted as illustrated above.
The line after the table provides information about the supplier with whom the largest order is placed. The full name of the supplier should be displayed, followed by a single space, followed by their formatted phone number, followed by a single space, followed by the cumulative cost for that supplier. The cumulative cost should be surrounded by square brackets, without any whitespace surrounding the number and displayed with 2 decimal numbers.
In addition to the output file, the same output should also appear on the screen.
Note that the example output table is not exactly related to the input examples provided here. Indeed, the output depends on 4 input files. The input and sample output provided here are just examples to indicate the format of all of the files. You should create your own files and stick to the structure described here.The TAs will evaluate your assignment with different input files.
Stick to what the customer has requested as format. Do not try to make it "nicer" or "more practical", or anything else. This is what the customer wants.
General Guidelines
In addition to making sure that your code runs properly, we will also check that you follow good programming practices. For example, divide the problem into smaller sub-problems, and write functions to solve those sub-problems so that each function has a single purpose; use the most appropriate data structures for your algorithm; use concise but descriptive variable names; define constants instead of hardcoding literal values throughout your code; include meaningful comments to document your code, as well as docstrings for all functions; and be sure to acknowledge any collaborators/references in a header comment at the top of your Python file.
Restrictions for this assignment:you cannot use break/continue, and you cannot import any modules. Doing so will result in deductions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started