I am new to programming and was wondering if anyone can help me. I have created a program below that enables me to write to the text file. I have a third Column called flower_quantity. I was wondering how I can update the text file with the code below without overwriting the flower_quantity.
def feature_4(flower_file='flowers.txt'):
flower_update = input("Enter the name of the flower you wish to change the price:"
"Lily, Rose, Tulip, Iris, Daisy, Orchid, Dahlia, Peony")
flower_new_price = input("Enter the updated price of the flower")
flower, price = [], []
with open(flower_file) as amend_price:
for line in amend_price:
spt = line.strip().split(",")
flower_price = int(spt[1])
flower_name = str(spt[0])
if flower_name == flower_update :
price.append(flower_new_price)
else:
price.append(flower_price)
flower.append(flower_name)
with open(flower_file, "w") as f_:
for i, v in enumerate(flower):
f_.write("{},{}\n".format(v, str(price[i])))
print("The new price of", flower_update, "is", flower_new_price)