Advertisement
teslariu

f2

Jul 10th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Script que crea un archivo celsius.txt y le almacena varios datos, luego
  6. crea otro archivo farenheit.txt con la conversión de los valores de
  7. celsius.txt
  8. """
  9.  
  10. # crear celsius.txt
  11. f = open('celsius.txt','x')
  12. datos = ['14.2ºC\n', '15.2ºC\n', '-25ºC\n', '58.6ºC\n', '-5ºC\n']
  13.  
  14. # existen dos maneras de guardar los datos:
  15. # forma 1
  16. # for dato in datos:
  17. #     f.write(dato)
  18. # forma 2
  19. f.writelines(datos)
  20. f.close()
  21.  
  22. # creo el archivo farenheit
  23. f = open('farenheit.txt', 'x')
  24.  
  25. # almaceno los valores
  26. for dato in datos:
  27.     temperatura, escala = dato.split("º")
  28.     temperatura = float(temperatura)*9/5 + 32
  29.     f.write("{:.1f}ºF\n".format(temperatura))
  30.  
  31. # cierro el archivo
  32. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement