""" Exercise 4.4 from "A primer on...". Read several temperature values from a file containing both text and numbers. Solution method: - Skip the first three lines - Process the rest with a for loop, using split() to extract the last item on each line. """ #empty list to be filled with values: Fvals = [] with open('Fdeg.txt', 'r') as infile: for i in range(3): infile.readline() for line in infile: words = line.split() F = words[-1] Fvals.append(float(F)) #now compute the C values and store in a list: Cvals = [] for F in Fvals: C = (F - 32) * 5 / 9 Cvals.append(C) #traverse both lists and write numbers to file: with open('FCdeg.txt','w') as outfile: for F, C in zip(Fvals, Cvals): outfile.write(f'{F:6.2f} {C:6.2f} \n') """ Terminal> python f2c_file_read_write.py (no output to the screen, only a new file) """