给我一些思路,或者实例,那个感觉无从下手,无论是def还是其他的都可以,谢谢
import random
a = [str(random.uniform(-200, 200)) + "\n" for i in range(15)]
with open("temps_input.txt", "w") as f:
f.writelines(a)
def covert_temps(F):
C = (F - 32) / 1.8
return C
with open("temps_input.txt", "r") as f:
F = f.readlines()
C = [str(covert_temps(float(i[:-2]))) + "\n" for i in a]
with open("temps_output.txt", "w") as f:
f.writelines(C)