2011/9/16 Victor Ramirez <[email protected]>:
> Si se trata de un número entero:
> while 1:
>     num = raw_input("Escribe un número: ")
>     if num.isdigit():
>         num = int(num)
>         break

Para un número decimal:

while True:
....num= raw_input('Escribe: ')
....try:
........num=float(num)
........break
....except ValueError:
........pass

Ahí directamente intenta convertirlo, y si no puede, te lo pide otra vez.
_______________________________________________
Python-es mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/

Responder a