Latest web development tutorials

Python incluye ejercicios 97

Python 100 Li Python 100 Li

Título: Introduzca algunos caracteres del teclado, los puso uno a uno hasta el disco hasta que introduzca una fecha #.

Análisis del programa: Ninguno.

Código fuente:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    from sys import stdout
    filename = raw_input('input a file name:\n')
    fp = open(filename,"w")
    ch = raw_input('input string:\n')
    while ch != '#':
        fp.write(ch)
        stdout.write(ch)
        ch = raw_input('')
    fp.close()

La salida del ejemplo anterior es:

input a file name:
a
input string:
b
b
c
c#

Python 100 Li Python 100 Li