Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Programa que lee un archivo de temperaturas en ºC, las pasa a
- ºF y luego crea otro archivo
- """
- # creo el archivo centigrado.txt
- f = open("centigrado.txt","x")
- lineas = ['10.258ºC\n', '-14.001ºC\n', '-0.2589652ºC\n']
- f.writelines(lineas)
- f.close()
- # abro el archivo "centigrado.txt" y leo su contenido
- f = open("centigrado.txt","r")
- lineas = f.readlines()
- f.close()
- # creo el archivo 'farenheit.txt':
- f = open("farenheit.txt","x")
- # calcular las temperaturas y almaceno en farenheit
- for linea in lineas:
- temp, escala = linea.split("º")
- temp = float(temp) * 1.8 + 32
- f.write("{:.2f}ºF\n".format(temp))
- # cierro los archivos
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement