[Tutor] I'm puzzled

Vincent Zee zenzee at xs4all.nl
Mon Jan 23 01:20:18 CET 2006


On Monday, 23 January 2006 at 10:59:24 +1100, Shuying Wang wrote:
> I'm guessing when you did that, you got something like an IndexError.
> That's because you didn't check the length of "a" from raw_input and
> accessed a nonexistent array element (a string is an array of
> characters). So if you changed the line:
> elif a[0] == '-' and a[1:].isdigit():
> to :
> elif len(a) > 1 and a[0] == '-' and a[1:].isdigit():
> 
> I expect you'll get what you want.
> 

Hi Shuying,

thank you for your solution.

/\
Vincent


More information about the Tutor mailing list