Trying to input text file (text #1) and output to another text file (text#2) in the following format. Running into an error. I am new to Python and any help would be appreciated.
Text #1
$1120.47 $944.42
$72.29 $588.23
$371.21 $2183.84
Text #2
$ 1120.47 $ 944.42 $ 2064.89
$ 72.29 $ 588.23 $ 660.52
$ 371.21 $ 2183.84 $ 2555.05
What I have so far:
inputfilename= input('Enter sales file name: ')
outputfilename=input('Enter name for total sales file: ')
with open(inputfilename, 'r') as i, open(outputfilename, 'w') as o:
for line in i:
fst_sale, lst_sale = line.split(' ')
fst_sale = float(fst_sale[1:])
lst_sale = float(lst_sale[1:])
tot_sale = fst_sale + lst_sale
new_line = ''.join(
['$' + str(x).rjust(10)
for x in [fst_sale, lst_sale, tot_sale]]
)
o.write(new_line + '\n')
I get this error when I hit run:
fst_sale, lst_sale = line.split(' ')
ValueError: not enough values to unpack (expected 2, got 1)