[Tutor] how to accept an integer?

Jerry Hill malaclypse2 at gmail.com
Wed Dec 5 22:58:42 CET 2007

On Dec 5, 2007 4:46 PM, Bryan Fodness <bryan.fodness at gmail.com> wrote:
> On Dec 5, 2007 4:16 PM, Jerry Hill <malaclypse2 at gmail.com> wrote:
> > speed = int(raw_input(prompt))
> Is this how ALL known integers should be input?

I don't think I understand the question.  If you are prompting your
user to enter an integer from the console, then yes, this is the
general way you should do it, probably wrapped in a try/except block.

You certainly don't have to do it all in one line like that.  Instead,
you could split it up into component parts, like this:

prompt = "Please enter a number between 1 and 10:\n"
user_input = raw_input(prompt)
    user_number = int(user_input)
except ValueError:
    print "You did not enter a number."


More information about the Tutor mailing list