I am trying to create a loop that will format, space, and align the 1st text to match the 2nd text. I am inputting text 1 from a txt file and I want it to output text 2 into a txt file. The syntax should print text #2 with the 3rd column summed.
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
This is what I have so far...you can tell this is only my 2nd week writing python.:) Any help would be appreciated.
inputfilename= input('Enter sales file name: ')
outputfilename=input('Enter name for total sales file: ')
infile=open(inputfilename, "r")
outfile=open(outputfilename, "w")
salessequence=infile.readlines()
for sale in salessequence:
splitsale=sale.strip().split(" ")
firstsale=splitsale[0]
lastsale=splitsale[1]
dollarsign1=firstsale[0:1]
firstsale2=firstsale[1:]
lastsale2=lastsale[1:]
total=firstsale2 + lastsale2
print(total, file=outfile)
infile.close()
outfile.close()
print('All finished')