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
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