teslariu

python

Feb 27th, 2021 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Programa que lee temperaturas en ºC de un archivo centigrado.txt y crea
  6. otro archivo llamado farenheit.txt con las temperaturas convertidas
  7. """
  8. # creo centigrado.txt
  9. f = open("centigrado.txt", "x")
  10. datos = ["10ºC\n","-14.58ºC\n","101.2ºC\n","-0.01ºC\n"]
  11. f.writelines(datos)
  12. f.close()
  13.  
  14. # abro el archivo centigrado.txt y leo su contenido
  15. f = open("centigrado.txt","r")
  16. lineas = f.readlines()
  17. f.close()
  18.  
  19. # creo el archivo farenheit.txt
  20. f = open("farenheit.txt", "x")
  21.  
  22. # convierto cada línea de ºC --> ªF
  23. for linea in lineas:
  24.     temp, escala = linea.split("º")
  25.     temp = float(temp) * 1.8 + 32
  26.     f.write("{:.2f}ºF\n".format(temp))
  27.  
  28. f.close()
Add Comment
Please, Sign In to add comment