Advertisement
teslariu

files

Jul 22nd, 2021
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1.     'x'            crea un nuevo archivo y lo abre para escribir
  2.     'a'            abre para escritura sin borrar el contenido (append)
  3.     'b'            modo binario
  4.     't'            modo texto (default)
  5.     '+'            abre para lectura y escritura
  6.     'U'            universal newline mode (deprecated)
  7. ========================================================================
  8.  
  9. """
  10.  
  11. # creo celsius.txt
  12. f = open('celsius.txt','x')
  13.  
  14. # añado 4 valores
  15. datos = ['10ºC\n', '-12.5ºC\n', '11ºC\n', '0.25ºC\n']
  16. for dato in datos:
  17.    f.write(dato)
  18.    
  19. # cierro el archivo
  20. f.close()
  21.  
  22. # lo abro de nuevo para agregarle 1 valor más
  23. f = open('celsius.txt','a')
  24. f.write("12.8ºC\n")
  25.  
  26. # cierro celsius.txt
  27. f.close()
  28.  
  29. # a los datos le agrego el último valor
  30. datos.append("12.8ºC\n")
  31.  
  32. # creo farenheit.txt
  33. f = open("farenheit.txt", "x")
  34.  
  35. # guardo los datos en farenheit
  36. for dato in datos:
  37.    temperatura, escala = dato.split("º")
  38.    temperatura = float(temperatura) * 1.8 + 32
  39.    f.write("{:.1f}ºF\n".format(temperatura))
  40.    
  41. # cierro el archivo
  42. f.close()
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement