[Tutor] Checking for int only
alan.gauld at blueyonder.co.uk
Mon Jun 28 18:58:28 EDT 2004
> How do you test for something to make sure that it is an int
> and not anything else so that when you ask them to enter a
> number they can only enter a number and not any other character.
One of the Python mantras is that its better to ask forgiveness
Try converting it to an int() if that doesn't work get them
to try again:
val = int(raw_input(....))
print "Couldn't read that as a number, try again...
More information about the Tutor