Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

following section. Input File You will be given only one input file sample which contains product names and product counts information in a certain format.

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
following section. Input File You will be given only one input file sample which contains product names and product counts information in a certain format. The name of the input file is products.txt. Each line of the input file will contain product information as in the following format; P1_Picount - P2-P count -... -P-P,count Ex: water_2-chocolate_3-cracker_35 Each product information will be separated with a dash ("-") character, and there will be an underscore ("_") character between the name of the product and the count of the product as a positive integer. You can assume the file information will be given in correct format. So, you don't have to perform any format check. You may assume that product names will not contain any "-" or characters. You cannot make assumptions about the length of the product names, or the digit count in product count information. There can be any number of products on the same line Product names are case insensitive. It means that "WATer" and "Water" are considered the same products. Please keep in mind that a product can occur several times in the same line of file or in different lines. You can assume that there will be no empty lines in the file. However, you cannot make any assumptions on the number of lines of this file. Besides, the lines might end or start with space, tab or other whitespace characters. Keep . For a sample input file, you may check out the products.txt provided with this assignment. Please note that we will use another file while grading your take-home exams. The content of the file will most probably change for grading purposes, but the name of the file will remain the same; that is, it will always be "products.txt". Functions, Inputs and Outputs Since, you cannot change the main part of the program you will need to implement functions that are being used in the main part. The details about these functions are explained below. It is extremely important to follow this order with the same format since we automatically process your programs. Also, prompts of the input statements to be Since, you cannot change the main part of the program you will need to implement functions that are being used in the main part. The details about these functions are explained below. It is extremely important to follow this order with the same format since we automatically process your programs. Also, prompts of the input statements to be used have to be exactly the same as the prompts of the "Sample Runs". Thus, your work will be graded as O unless the order is entirely correct. There are three functions that you definitely will need to implement in your program. > import_inventory() is the function to be implemented to read the data from the text file into a dictionary that holds the counts of the products. Therefore, in this function, you will create an empty dictionary, read the data from products.txt into this dictionary, and then return the dictionary as a returning value. In the returning dictionary, you should keep product names as keys, and total product counts with this name as integer values. sell_product is the function to be implemented to update the counts of the products in the inventory after a sell process. This function takes only one parameter which is the inventory dictionary that was created in import_inventory function, sell_product() function does not return any returning value. In sell_product() function, the names of the products and the counts of In sell product() function, the names of the products and the counts of the products to be sold will be taken as a string input. Product names are again case-insensitive, which means that some of the letters could be entered in upper-case, whereas some of them could be entered in lower-case. So, you need to normalize them before searching from the dictionary. The format of the products to be sold input will be as following; P1-P count - P2-p2count -...-Pn-P,count Ex: Water_1-ChocolatE_2-water_21 Each product information will be separated with a dash ("-") character and there will be an underscore ("_") character between the name of the product and the count of the product. You can assume the file information will be given in correct format. So, you don't have to perform any format check. You cannot make assumptions about the length of the product names, or the digit count in product count information. There can be any number of products on the same line . Please keep in mind that a product can occur several times in this input. Your program should handle each product separately even if the same product occurs several times. . You may assume that product counts will always be an integer greater than 0. After selling the product if the remaining count is zero, that product should be removed from the dictionary (hint: use pop() method of dictionary). After the product information to sell input is taken, this function (sell_product() should compare each product count in the input and the product count in the inventory. According to this comparison, if there are enough products in inventory, then your function should update the count in the inventory by decreasing the product count by the product to be sold, and give the count of the sold product and the name of the product (with lowercase letters) as output. For example: "10 water sold. If we have this particular product in inventory, but this product's count value is less than users request, then your program should output an appropriate error message saying there is not enough product (with lowercase letters) in inventory. For example; "There is not enough water in inventory." If there is not even one product of the product requested to be sold in inventory then your program should output an appropriate error message saying that product with lowercase letters) doesn't exist in inventory for example water does not exist in inventory. show ne function to be implemented to print the current products (with lowercase letters) and their counts in inventory in alphabetical order (in an ascending way). If there are no products in the inventory, then your program should print an appropriate message; "Inventory is empty!". show_remaining() function does not return any returning value. It's very important to have the same function names, same number of parameters, and same returning values for these functions as explained in THE document. Otherwise, the given main program will not work with your functions. You may add additional functions if you need without changing the main part. Please see the Sample Runs section for some examples. Important Remarks on Working with Files Please do NOT use the following two lines to upload the txt file to Colab Anstead Sample Runs Below, we provide some sample runs of the program that you will develop. The italic and bold phrases are inputs taken from the user. You have to display the required information in the same order and with the same words and characters as below. Sample Run 1 [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 3 Terminating... Sample Run 2 [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 4 Invalid input Sample Run 2 * [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 4 Invalid input! [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 3 Terminating Sample Run 3 [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 1 Please enter products to sell: COKE_6-water_2 6 coke sold. 2 water sold. [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 3 Terminating. Sample Run 4 [1] Sell products [2] Show remaining inventory Sample Run 4 [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 2 candy : 321 cheese : 171 chips : 80 chocolate : 78 coke : 244 gum: 203 soda : 935 water : 219 [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 3 Terminating... Sample Run 5 [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 2 candy : 321 cheese : 171 chips : 80 chocolate : 78 coke : 244 gum: 203 soda : 935 water : 219 *--- [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 1 Please enter products to sell: COKE_6-water_2 Please enter products to sell: COKE 6-water_2 6 coke sold. 2 water sold. [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 1 Please enter products to sell: cracker_12-candy_5 cracker does not exist in inventory. 5 candy sold. [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 2 candy : 316 cheese : 171 chips : 80 chocolate : 78 coke : 238 gum: 203 soda : 935 water : 217 [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 3 Terminating... Sample Run 6 Sample Run 8 ---- [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 2 candy : 321 cheese : 171 chips : 80 chocolate : 78 coke : 244 gum: 203 soda : 935 water : 219 [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 1 Please enter products to sell: chocoLATE_75-chocolate_4 75 chocolate sold. There is not enough chocolate in inventory. [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 1 Please enter products to sell chocolate_3-chocolate. 5 3 chocolate sold. chocolate does not exist in inventory. 1 Sell broducts products = import_inventory() decision while decision != "3": print("*- print("[1] Sell products") print("[2] Show remaining inventory") print("[3] Terminate") decision = input("Please enter your decision: ") print(" if decision sell_product input("Please enter products to sell: ") sell_product (products) I elif decision "2": show_remaining (products) elif decision print("Terminating...") else: print("Invalid input!") water 5-CHOCOLATE 14 coke 12-Cheese 5 water_2-water 12 Um 4-chips 9 water 12 soda 6-candy. 48-CORE 24 chocolate 12-GUM 7 soda_3-coke 1 WATER 4 Ater 8 gum_2-candy_4-coke_5-water_3-cheese_6 cheese_4-chips 5-soda_128-cheese 4 candy 7-water 2-cheese_6-gum_8-coke_3 gum_ S-gum_8-gum 5 gum 2-candy_4-coke_5-water_3-cheese_6 cheese_4-chips_5-soda_128-cheese_4 candy_7-water_2-cheese_6-gum_8-coke_3 gum_5-gum 8-gum 5 water_5-CHOCOLATE 14 coke_12-Cheese_5 water_2-water_12 gum_4-chips_9-water 12 soda_E-candy_48-COKE_24 chocolate_12-GUM_7 soda_3-coke_1 WATER 4 Water B coke_12-cheese_5 water 2-water_12 gm_4-chips_9-watez 12 soda_-candy_48-CORE_24 cheese_4chs_5-soda 12-cheese_4 candy_7-water_2-cheese_6-gun-coke_8 gum_5-gum-gum_ ware_5-CHOCOLATE_14 coke 12-cheese 5 WEE_2-szek_2 Fehlster coke 12-Cheese 3 water 2-wateR_12 gUm_4-chips 9-water_12 a0da_6-candy_48-COKE_24 cheese_4-chips 5-soda_128-cheese 4 candy_7-water_2-cheese_6-gum_8-coke_3 gum_5-gum 8-gum 5 water_5-CHOCOLATE 14 coke 12-Cheese 5 water 2-wateR 12 gum_4-chips_9-water 12 30da_6-candy_48-COKE_24 chocolate_12-GUM 7 soda_3-coke_1 WATER_4 Water & gum_2-candy_4-coke_5-water_3-cheese_6-gum_2-candy_4-coke_5-water_3-cheese_6 coke 12-Cheese_5 water_2-wateR_12 gum_4-chips_9-water 12 soda_6-candy 48-COKE_24 gum_2-candy 4-coke_5-water_3-cheese_6 cheese 4-chips_5-soda 128-cheese_4 candy_7-water_2-cheese_6-gram_e-coke_3 gum_5-gam_argum_5 gum_2-candy_4-coke_5-water_3-cheese, cheese 4-5-oda 128-cheest candy_THE-LE-cheese_gumienie gum_cana Reswatekeese cheese HERE heese candy_reneane_6-94-RELE cards 4-cewetentes BH Flash

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

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago

Question

Additional Factors Affecting Group Communication?

Answered: 1 week ago