The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 313 Weeks Ago, 6 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
2. a. You need to create a file of inventory_items which has the following items.  Use a loop to read in each value until exit is entered for the item_name.  This input represents the item_name, number_sold, price_item, and cost_item.
Blue Pens
400
1.39
0.75
No. 2 Pencils
1000
0.25
0.1
Notebooks
500
6.99
3.47
Â
For each item entered, create a string with the values separated by commas.  One item is shown as an example.
Blue Pens, 400, 1.39, 0.75
Â
Write out each item string to file named inventory_items.txt.
Â
b. Read in the lines of text and split up string line into a list.  Access the appropriate list elements in order to perform the following calculation for the profit: number_sold * (price_item - cost_item).  Print out the name of the item and the profit with two decimal places of precision.
Â
(BONUS) Sum up the profit in order to compute the total profit.
Â
THE FOLLOWING ATTACHED FILE IS WHAT I HAVE, BUT I CAN'T FIGURE OUT HOW TO PRINT THE SUM of number_sold * price_item and then print out the profit all in the .txt file
def main():
   item_name=['Blue Pens', 'No.2 Pencil', 'Notebooks']
   number_sold=[400,1000,500]
   price_item=[1.39, 0.25, 6.99]
   cost_item=[0.75, 0.1, 3.47]
   file_opened = False
   try:
       count=len(item_name)
       print (count)
      Â
       output_file=open("inventory_items.txt","w")
       file_opened=True
       for i in item_name, number_sold,price_item,cost_item:
           print (i,file=output_file)
      Â
      Â
  Â
  Â
   except KeyboardInterrupt:
       print("Exiting...")
   except PermissionError: #dont have permission
       print ("Permission Error")
   except IsADirectoryError:
       print("Directory is specified and not a file")
   except FileNotFoundError:
       print("File not found")
   finally:
       if file_opened:
           output_file.close()#closes file
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly