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 program and came up with this code: f = open('data.txt', 'w+') while(True): name = input("Enter item name or Enter to quit ") if name == "" : break cost = input("Enter item's regular price ") reduction = input("Enter reduction percent for sale ") f.write(name + ' ' + cost + ' ' + reduction + ' \n') f.close() print("File was created") i need program6_2.py
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 program and came up with this code:
f = open('data.txt', 'w+')
while(True):
name = input("Enter item name or Enter to quit ")
if name == "" :
break
cost = input("Enter item's regular price ")
reduction = input("Enter reduction percent for sale ")
f.write(name + ' ' + cost + ' ' + reduction + ' \n')
f.close()
print("File was created")
i need program6_2.py
f = open('data.txt', 'w+')
#f.write('ITEM\tREG.PRICE\tREDUCED\t\tSALE PRICE\n')
f.write(f"{'ITEM' : <10}{'REG.PRICE' : >10}{'REDUCED' : >10}{'SALE PRICE' : >18}\n")
while(True):
name = input("Enter item name or Enter to quit ")
if name == "" :
break
cost = input("Enter item's regular price ")
reduction = input("Enter reduction percent for sale ")
newCost = str(float(cost) - float(reduction))
f.write(f"{name : <10}{cost : >10}{reduction : >10}{newCost : >18}\n")
#f.write(name + "\t" + cost + "\t\t" + reduction + "\t\t" + newCost + "\n")
f.close()
print("File was created")
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images