Advertisement
teslariu

temp

Feb 24th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Programa que crea un archivo con temp expresadas en ºC
  5. y luego genera otro con las mismas temperaturas pero expresadas en ºF
  6. """
  7.  
  8. f = open("centigrado.txt","x")
  9.  
  10. datos = ['10ºC\n', '12.5ºC\n', '-18.4ºC\n', '100.22ºC\n']
  11.  
  12. f.writelines(datos)
  13. f.close()
  14.  
  15. f = open("centigrado.txt","r")
  16.  
  17. lineas = f.readlines()
  18. f.close()
  19.  
  20. f = open("farenheit.txt","x")
  21. for linea in lineas:
  22.     temp, escala = linea.split("º")
  23.     temp = float(temp) * 1.8 + 32
  24.     f.write("{:.2f}ºF\n".format(temp))
  25.  
  26. f.close()
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement