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.
program6_1.py
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.
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5bfd5d10-1146-4d37-bb0a-e9dee942923c%2F1dd1e6e3-6562-4c9f-946a-1fa54c3afd0c%2Fenyg2el_processed.png&w=3840&q=75)
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5bfd5d10-1146-4d37-bb0a-e9dee942923c%2F1dd1e6e3-6562-4c9f-946a-1fa54c3afd0c%2Fzdf6gw_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
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
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)