in python Write a program that the owner of Chica Chic could use to store data about her inventory in a text file. The program should prompt her to input the name, cost price, and quantity of each item of inventory. Each of these three data has to be written to its own line in the file. The program should loop to enable any number of inventory items to be stored and end when the item name is left blank (see Sample Output. User inputs are shown in blue). The program should end by closing the file and printing a file status message.Sample OutputEnter the name of the inventory item or ENTER to quit topsEnter the cost price of this item 24.99Enter the quantity in stock of this item 10A record was written to fileEnter the name of the inventory item or ENTER to quit shortsEnter the cost price of this item 29.95Enter the quantity in stock of this item 12A record was written to fileEnter the name of the inventory item or ENTER to quit sandalsEnter the cost price of this item 19.79Enter the quantity in stock of this item 8A record was written to fileEnter the name of the inventory item or ENTER to quitThe file was created successfully and closedprogram6_2.pyNow write another program that reads her inventory file, displays all data for each item, and reports on the inventory value. The cost value of each item and the cost value of the total inventory should be reported. Strive to duplicate the Sample Output below.Sample OutputChica Chic Inventorytops, $24.99 each, 10 in stock, value $249.90shorts, $29.95 each, 12 in stock, value $359.40sandals, $19.79 each, 8 in stock, value $158.32End of fileTotal inventory value $767.62

Question
Asked Sep 30, 2019
389 views

in python

 

Write a program that the owner of Chica Chic could use to store data about her inventory in a text file. The program should prompt her to input the name, cost price, and quantity of each item of inventory. Each of these three data has to be written to its own line in the file. The program should loop to enable any number of inventory items to be stored and end when the item name is left blank (see Sample Output. User inputs are shown in blue). The program should end by closing the file and printing a file status message.
Sample Output
Enter the name of the inventory item or ENTER to quit tops
Enter the cost price of this item 24.99
Enter the quantity in stock of this item 10
A record was written to file
Enter the name of the inventory item or ENTER to quit shorts
Enter the cost price of this item 29.95
Enter the quantity in stock of this item 12
A record was written to file
Enter the name of the inventory item or ENTER to quit sandals
Enter the cost price of this item 19.79
Enter the quantity in stock of this item 8
A record was written to file
Enter the name of the inventory item or ENTER to quit
The file was created successfully and closed

program6_2.py
Now write another program that reads her inventory file, displays all data for each item, and reports on the inventory value. The cost value of each item and the cost value of the total inventory should be reported. Strive to duplicate the Sample Output below.
Sample Output
Chica Chic Inventory

tops, $24.99 each, 10 in stock, value $249.90
shorts, $29.95 each, 12 in stock, value $359.40
sandals, $19.79 each, 8 in stock, value $158.32
End of file
Total inventory value $767.62

check_circle

Expert Answer

Step 1

To create a python program which stores the inventory details such as name of item, cost of item and quantity of item in a text file named as inventory.txt. The file can store any number of entries until the user commands to stop. The python program is given below.

Step 2

Program code:

file= open("inventorty.txt","w")

while True:

  product = input("Enter the name of the inventory item or ENTER to quit ");

  if(product==""):

      break

  cost = float(input("Enter the cost price of this item "))

  quantity = int(input("Enter the quantity in stock of this item "))

  file.write(product+" "+str(cost)+" "+str(quantity)+" ")

  print("A record was written to file ")

file.close()

print("The file was created successfully and closed")

Step 3

The above program creates a text file named as inventory.txt and making entries in the files for the item names, prices and quantities. In the program, while loop is used to enter any number of items and end it when the user want...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: What is “ticket transfer” in lottery scheduling? Also, what is the primary benefit of ticket transfe...

A: Lottery scheduling:In an operating system, lottery scheduling is one of the scheduling algorithms fo...

question_answer

Q: Given the following snippet of C++ code: int int1 = -125;unsigned int uInt1 = int1;float float1 = in...

A: ConceptWhenever a negative number is assigned to a variable of any datatype, that number is first co...

question_answer

Q: When a process executes a fork() system call, a duplicate process (i.e. the child process) is create...

A: The “fork()” system call:The “fork()” system call is employed to create a new process called child p...

question_answer

Q: I am working on Python. I have been asked to write a program for this question. Write a program that...

A: The below source code will take the input from the user as many times as the user wants until the us...

question_answer

Q: I can't figure out what is wrong with my assembly code it seems to error out when I add the follow l...

A: Error:The statement “movl %eax, %rdx” gives an error saying that destination operand incorrect size.

question_answer

Q: tgis problem should be done with  while loop that much i know but after that’s im lost

A: In the given question nothing has been mentioned about the error calculations so we would not be abl...

question_answer

Q: In C++ Sort an array from largest to smallest (you may use one of the sorts we did, you just have to...

A: Program://include the required header files#include<iostream>using namespace std;//definition ...

question_answer

Q: in eclipse

A: In operator overloading, the type of arguments defines which function will be called at the run-time...

question_answer

Q: Make truth tables, then use them to create equations in SOP and POS format. Explain your steps.1) xy...

A: Truth table for the expression: F = xyz+ x~(yz) + ~(xyz)