Advertisement
teslariu

file

Apr 10th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Programa que lee un archivo de temperaturas en ºC, las pasa a
  6. ºF y luego crea otro archivo
  7. """
  8. # creo el archivo centigrado.txt
  9. f = open("centigrado.txt","x")
  10. lineas = ['10.258ºC\n', '-14.001ºC\n', '-0.2589652ºC\n']
  11. f.writelines(lineas)
  12. f.close()
  13.  
  14.  
  15. # abro el archivo "centigrado.txt" y leo su contenido
  16. f = open("centigrado.txt","r")
  17. lineas = f.readlines()
  18. f.close()
  19.  
  20. # creo el archivo 'farenheit.txt':
  21. f = open("farenheit.txt","x")
  22.  
  23. # calcular las temperaturas y almaceno en farenheit
  24. for linea in lineas:
  25.     temp, escala = linea.split("º")
  26.     temp = float(temp) * 1.8 + 32
  27.     f.write("{:.2f}ºF\n".format(temp))
  28.    
  29. # cierro los archivos
  30. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement