Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Programa que lee temperaturas en ºC de un archivo centigrado.txt y crea
- otro archivo llamado farenheit.txt con las temperaturas convertidas
- """
- # creo centigrado.txt
- f = open("centigrado.txt", "x")
- datos = ["10ºC\n","-14.58ºC\n","101.2ºC\n","-0.01ºC\n"]
- f.writelines(datos)
- 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")
- # convierto cada línea de ºC --> ªF
- for linea in lineas:
- temp, escala = linea.split("º")
- temp = float(temp) * 1.8 + 32
- f.write("{:.2f}ºF\n".format(temp))
- f.close()
Add Comment
Please, Sign In to add comment