[Tutor] I'm puzzled
Vincent Zee
zenzee at xs4all.nl
Mon Jan 23 00:59:40 CET 2006
On Sunday, 22 January 2006 at 15:54:06 -0800, Danny Yoo wrote:
>
> > Why will this little program crash when you enter the enter key?
>
> [program cut]
>
> Hi Vincent,
>
> What do you mean by "crash"? Do you get an error message? If so, can you
> show us?
>
>
> It will also help to think to try playing the situation out without
> preconceptions. In the beginning of the loop, at:
>
> > a = raw_input('number? ')
>
> what does 'a' contain when you hit enter?
>
>
Hi Danny,
the program works with any input except when you just hit the enter key.
vincent at zenzeebook:~/Desktop% python untitled.py
number?
Traceback (most recent call last):
File "untitled.py", line 12, in ?
elif a[0] == '-' and a[1:].isdigit():
IndexError: string index out of range
/\
Vincent
More information about the Tutor
mailing list