Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Script que crea un archivo celsius.txt y le almacena varios datos, luego
- crea otro archivo farenheit.txt con la conversión de los valores de
- celsius.txt
- """
- # crear celsius.txt
- f = open('celsius.txt','x')
- datos = ['14.2ºC\n', '15.2ºC\n', '-25ºC\n', '58.6ºC\n', '-5ºC\n']
- # existen dos maneras de guardar los datos:
- # forma 1
- # for dato in datos:
- # f.write(dato)
- # forma 2
- f.writelines(datos)
- f.close()
- # creo el archivo farenheit
- f = open('farenheit.txt', 'x')
- # almaceno los valores
- for dato in datos:
- temperatura, escala = dato.split("º")
- temperatura = float(temperatura)*9/5 + 32
- f.write("{:.1f}ºF\n".format(temperatura))
- # cierro el archivo
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement