> Why will this little program crash when you enter the
> enter key?
>
> while True:
> a = raw_input('number? ')
> if a.isdigit():
> print 'isdigit'
> elif a[0] == '-' and a[1:].isdigit():
You could instead use
elif a.startswith('-') and a[1:].isdigit():
as the empty string certainly doesn't start with '-', and python won't check
the second half after the first check evaluates false.
> print '- + isdigit'
> elif a == 'q':
> break
> else:
> print 'no digit'
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor