[Tutor] I'm puzzled
Vincent Zee
zenzee at xs4all.nl
Mon Jan 23 01:24:56 CET 2006
On Sunday, 22 January 2006 at 18:11:09 -0600, Hugo González Monteverde wrote:
> Hi Vincent,
>
> > the program works with any input except when you just hit the enter key.
>
>
> To be able to understand why is the crash, take a look at what the
> interpreter tells you:
>
> > File "untitled.py", line 12, in ?
> > elif a[0] == '-' and a[1:].isdigit():
> > IndexError: string index out of range
>
> IndexError is raised whan you try to access an element in a list or
> string, an element that does not exist. In the case where you only press
> enter, what is the content of a???? How many characters? (hint, you may
> try to
>
Hi Hugo,
thank you for your reply.
What confused me was the fact that the isdigit method didn't complain
about the empty string, so I assumed that indexing an empty string
wouldn't be a problem (:-))
But now I think of it that wouldn't be logical.
Sometimes the 'intelligence' of python makes me lazy (;-))
/\
Vincent
More information about the Tutor
mailing list