teslariu

archi

Jun 5th, 2021
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Script que crea un archivo de temperaturas en ºC, lo cierra, lo vuelva a
  6. abrir y crea otro con las mismas temperaturas pero expresaas en ºF
  7. """
  8. #creo el archivo 'farenheit.txt', lo cargo con datos y lo cierro
  9. f = open("centigrados.txt","x")
  10. datos = ['10ºC\n', '-22.5ºC\n', '11.2ºC\n','24.1ºC\n','-0.2ºC\n']
  11. f.writelines(datos)
  12. f.close()
  13.  
  14. # abro un archivo y leo su contenido
  15. f = open("centigrados.txt","r")
  16. lineas = f.readlines()
  17. f.close()
  18.  
  19. # creo el otro archivo
  20. f = open("farenheit.txt","x")
  21.  
  22. # convierto cada línea de ºC a ºF
  23. for linea in lineas:
  24.     temp, escala = linea.split("º")
  25.     temp = float(temp) * 1.8 + 32
  26.     f.write("{:.1f}ºF\n".format(temp))
  27.    
  28. # cierro el archivo
  29. f.close()
Advertisement
Add Comment
Please, Sign In to add comment