Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- Script que crea un archivo con temperaturas expresadas en ºC, luego genera otro archivo
- con sus temperaturas equivalentes en ºF
- ========= ===============================================================
- Character Meaning
- --------- ---------------------------------------------------------------
- 'r' open for reading (default)
- 'w' open for writing, truncating the file first
- 'x' create a new file and open it for writing
- 'a' open for writing, appending to the end of the file if it exists
- 'b' binary mode
- 't' text mode (default)
- '+' open a disk file for updating (reading and writing)
- 'U' universal newline mode (deprecated)
- ========= ===============================================================
- The default mode is 'rt' (open for reading text).
- """
- # creo un archivo vacío para agregarle datos
- f = open("centigrados.txt","w")
- datos = ["25ºC\n", "-15.258ºC\n", "25.1ºC\n", "0ºC\n"]
- # escribo cada elemento de dato como una línea
- f.writelines(datos)
- f.close()
- # abro el archivo en modo lectura para mostrar su contenido
- f = open("centigrados.txt")
- lineas = f.readlines()
- for linea in lineas:
- print(linea.strip())
- # creo el otro
- f = open("farenheit.txt","w")
- for dato in datos:
- temp, escala = dato.split("º")
- temp = float(temp) * 1.8 + 32
- f.write(f"{temp:.1f}ºF\n")
- # cierro todo
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement