Respuesta :
with open('celcius.dat', 'r') as fIn, open('fahrenheit.dat', 'w') as fOut:
for line in fIn:
fahrenheit = 9.0 / 5.0 * float(line) + 32
fOut.write("%.1f\n" % fahrenheit)
You can control the number of decimals in the formatting clause in the write statement.
The program reads in the Celcius temperature in a file and creates a file with the temperature value expressed on Fahrenheit. The program written in python 3 goes thus ;
with open('celcius.dat', 'r') as file1
, open('fahrenheit.dat', 'w') as file2:
#opens the Celcius file in read mode and creates a new file fahrenheit.dat in write mode
for line in file1:
#loop through each line in the Celcius file
fahrenheit = 9.0 / 5.0 * float(line) + 32
#using the fahrenheit conversion formula, convert the Celcius temperatures and assign to the fahrenheit variable
file2.write("%.1f\n" % fahrenheit)
#f write the converted values into the file2
Learn more : https://brainly.com/question/19323897