Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'x' crea un nuevo archivo y lo abre para escribir
- 'a' abre para escritura sin borrar el contenido (append)
- 'b' modo binario
- 't' modo texto (default)
- '+' abre para lectura y escritura
- 'U' universal newline mode (deprecated)
- ========================================================================
- """
- # creo celsius.txt
- f = open('celsius.txt','x')
- # añado 4 valores
- datos = ['10ºC\n', '-12.5ºC\n', '11ºC\n', '0.25ºC\n']
- for dato in datos:
- f.write(dato)
- # cierro el archivo
- f.close()
- # lo abro de nuevo para agregarle 1 valor más
- f = open('celsius.txt','a')
- f.write("12.8ºC\n")
- # cierro celsius.txt
- f.close()
- # a los datos le agrego el último valor
- datos.append("12.8ºC\n")
- # creo farenheit.txt
- f = open("farenheit.txt", "x")
- # guardo los datos en farenheit
- for dato in datos:
- temperatura, escala = dato.split("º")
- temperatura = float(temperatura) * 1.8 + 32
- f.write("{:.1f}ºF\n".format(temperatura))
- # cierro el archivo
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement