Advertisement
teslariu

Untitled

Jan 8th, 2021
130
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. Programa que crea un archivo con temperaturas expresadas en ºC y que
  5. luego cree otro archivo con dichas temperaturas pero en ºF.
  6. """
  7.  
  8. # creo el archivo con temp en ºC
  9. f = open("centigrados.txt","w")
  10. datos = ['10ºC\n', '12.5ºC\n', '25ºC\n', '-25ºC\n', '14.85ºC\n', '-12.585ºC\n']
  11.  
  12. f.writelines(datos)
  13. f.close()
  14.  
  15. # abro el archivo para leer los datos
  16. f = open("centigrados.txt","r")
  17. lineas = f.readlines()
  18. f.close()
  19.  
  20. # creo el archivo farenheit
  21. f = open("farenheit.txt","w")
  22.  
  23. # pasar de ºC --> ºF cada línea
  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. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement