I have typed a program to compare vehicle A price (v_priceA) to various other vehicle prices in a carprices.txt text file which are in a new line.
The result should be a new text called highprices.txt file with all the prices greater than the price of Vehicle A in a newline and the associated line number from carprices.txt
My problem is am able to generate two text files that has the line number of the greater file and another with the greater price, instead of the greater price itself and line number together. I need to fix this.
Vehicle A price: 2500.50
v_priceA = 2500.50
a_file = 'carprices.txt'
with open(a_file, 'r') as document:
values = [x for x, value in enumerate(document) if float(value) > v_priceA]
new_file = open('highpriceposition.txt', 'w')
for x in values:
new_file.write(str(x) + '\n')
new_file.close()
a_file = 'carprices.txt'
with open(a_file, 'r') as document:
values = [value for value in document if float(value) > v_priceA]
with open('highprice.txt', 'w') as f:
for x in values:
f.write(str(x)+'\n')
positionprice.txt
2 2900.00
3 3500.50
5 25000.30
6 45000.50