BetterBuy is having a sale. Write a program that uses a while loop to store to a file the names, regular prices, and price reductions (as percents) for selected items in the promotion. The program should enable the user to enter this data from the keyboard as shown below . Each datum should be stored on its own line in the file.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

program6_1.py
BetterBuy is having a sale. Write a program that uses a while loop to store to a file the namesregular prices, and price reductions (as percents) for selected items in the promotion. The program should enable the user to enter this data from the keyboard as shown below . Each datum should be stored on its own line in the file.

 

 

I already finished this section, i just need the code to program6_2.py

 

Enter item name or Enter to quit laptop
Enter item's regular price 899.99
Enter reduction percent for sale 25
Enter item name or Enter to quit router
Enter item's regular price 229.95
Enter reduction percent for sale 40
Enter item name or Enter to quit printer
Enter item's regular price 399.99
Enter reduction percent for sale 20
Enter item name or Enter to quit monitor
Enter item's regular price 425.79
Enter reduction percent for sale 30
Enter item name or Enter to quit
File was created
Transcribed Image Text:Enter item name or Enter to quit laptop Enter item's regular price 899.99 Enter reduction percent for sale 25 Enter item name or Enter to quit router Enter item's regular price 229.95 Enter reduction percent for sale 40 Enter item name or Enter to quit printer Enter item's regular price 399.99 Enter reduction percent for sale 20 Enter item name or Enter to quit monitor Enter item's regular price 425.79 Enter reduction percent for sale 30 Enter item name or Enter to quit File was created
ITEM
REG. PRICE
REDUCED
SALE PRICE
laptop
899.99
225.00
674.99
router
229.95
91.98
137.97
printer
monitor
399.99
80.00
319.99
425.79
127.74
298.05
Transcribed Image Text:ITEM REG. PRICE REDUCED SALE PRICE laptop 899.99 225.00 674.99 router 229.95 91.98 137.97 printer monitor 399.99 80.00 319.99 425.79 127.74 298.05
Expert Solution
SOURCE CODE


with open("item_data.txt","a") as f:
 while True:
  item_name = input("Enter item name or Enter to quit: ")
  if not item_name:
   break
  regular_price = float(input("Enter item's regular price: "))
  sale_percent = input("Enter Reduction sale percent: ")
  f.write("{} {} {}\n".format(item_name.strip('\n'),regular_price,sale_percent.strip('\n')))

with open("item_data.txt","r") as f:
 print("ITEM NAME\t REG. PRICE\t REDUCED\t SALE PRICE")
 for line in f.readlines():
  item_name,regular_price,sale_percent = line.split()
  reduced_price = float(regular_price) * (int(sale_percent)/100)
  sale_price = float(regular_price) - reduced_price
  print(f"{item_name}\t\t {float(regular_price):.2f}\t\t {reduced_price:.2f}\t\t {sale_price:.2f}")

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY