""" Exercise 4.4 from "A Primer on... Read data from file, store data in lists, then write to another file in a different format. """ #Part 1: read and store in lists infile = open('Fdeg.dat','r') #skip the first three lines: for i in range(3): infile.readline() F_list = [] C_list = [] for line in infile: words = line.split() F = float(words[-1]) F_list.append(F) C = (F-32)*5.0/9 C_list.append(C) infile.close() #Part 2: write data in lists to a new file outfile = open('outfile.txt','w') for F,C in zip(F_list,C_list): outfile.write(f'{F:6.2f} {C:6.2f}\n') outfile.close() """ Terminal> python f2c_file_read_write.py Terminal> more outfile.txt 67.20 19.56 66.00 18.89 78.90 26.06 102.10 38.94 32.00 0.00 87.80 31.00 """