111k views
4 votes
python Write a program that will take a file named Celsius.dat that contains a list of temperatures in Celsius (one per line), and will create a file Fahrenheit.dat that contains the same temperatures (one per line, in the same order) in Fahrenheit

User Xose Lluis
by
5.5k points

1 Answer

4 votes

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\\" % fahrenheit)


You can control the number of decimals in the formatting clause in the write statement.

User Matthisk
by
5.7k points