Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- Programa que crea un archivo con temperaturas expresadas en ºC y que
- luego cree otro archivo con dichas temperaturas pero en ºF.
- """
- # creo el archivo con temp en ºC
- f = open("centigrados.txt","w")
- datos = ['10ºC\n', '12.5ºC\n', '25ºC\n', '-25ºC\n', '14.85ºC\n', '-12.585ºC\n']
- f.writelines(datos)
- f.close()
- # abro el archivo para leer los datos
- f = open("centigrados.txt","r")
- lineas = f.readlines()
- f.close()
- # creo el archivo farenheit
- f = open("farenheit.txt","w")
- # pasar de ºC --> ºF cada línea
- for linea in lineas:
- temp, escala = linea.split("º")
- temp = float(temp) * 1.8 + 32
- f.write("{:.2f}ºF\n".format(temp))
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement