Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

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
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_P,count - P2_P2count -...-Pn-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 this in mind while you're preprocessing the content of the file. elp Request edit access QOQAG- . 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 e 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 0 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_producto function does not return any returning value. 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 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 ("Lt) 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 . . same product occurs severar 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.remaining() is the 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 15 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! [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 3 Terminating... Requal 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 [3] Terminate Please enter your decision: 2 Icandy : 321 cheese : 171 chips i Bo Request edit Sample Run 6 * [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: SoDa_30-CHiPs_80-gum_33 30 soda sold. 80 chips sold. 33 gum sold. 8 8 8) Request edit access [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 1 Please enter products to sell: Gum_200-chocolate_12-water_4 There is not enough gum in inventory. 12 chocolate sold. 4 water sold. * [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 2 candy : 321 cheese : 171 chocolate : 66 coke : 244 gum: 170 soda : 905 water: 215 [1] Sell products [21 Show remaining inventory 161 Terminate Please enter your decision: 1 # DO NOT MODIFY THIS CODE CELL, DUST RUN IT products - import inventory("products.txt) decision while decision !- "3": print("---- -) print("[1] Sell products") print("[2] Show remaining inventory") print("[3] Terminate") decision input("Please enter your decision ) print(" 1) if decision1": sell product (products) elif decision-2": show remaining (products) elf decision : print Terminating...) else: Print Invalid input Traceback (most recent call last) NameError spython RULE 18655f697661 Type here to search 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 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-P count -...-Pn-P,count [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 1 Please enter products to sell: candy 321-cheese_171-chips_80 321 candy sold. 171 cheese sold. 80 chips sold. [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 1 Please enter products to sell: water_220-sodo_935-chips_20-coke_244-gum_203 There is not enough water in inventory. 935 soda sold. chips does not exist in inventory 244 coke sold. 203 gum sold (1) Se 1 products (2|Show remaining inventory 219 water sold. 78 chocolate sold. [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 2 Inventory is empty! [1] Sell products [2] Show remaining inventory [3] Terminate Please enter your decision: 3 Terminating

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_2

Step: 3

blur-text-image_3

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

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students explore these related Databases questions