i have two files containing lists and I would like to perform some manipulations with the numbers.
file 1:
- A 1
- B 2
- C 3
and file 2:
- A 4
- B 5
- C 6
I have written the following code to read in the files and then add list 1 and list 2 together. The code is as follows:
energy_file_in= open('test.dat', "r")
slab_file_in= open('pt3x_slab.dat', "r")
energy_in=energy_file_in.readlines()
slab_in=slab_file_in.readlines()
energy_file_in.close()
slab_file_in.close()
#write data
raw_data_1_file_out = open('ads_ene.dat', "w")
energy=[]
for i in energy_in:
energy=i.split()
for j in slab_in:
slab=j.split()
x = "%0.7f" %(float(float(energy[1]))+(float(slab[1])))
print>>raw_data_1_file_out,slab[0], x
The output it generates is not what I want. I just want it to generate a list showing
A 5
B 7
C 9
Pls can someone suggest where I am going wrong with this code.
Thank you