[Tutor] Convert String to Int

Alan Gauld alan.gauld at btinternet.com
Mon Jan 19 10:05:49 CET 2009


"Ian Egland" <echolynx at gmail.com> wrote

> I know that, should you want to get an int from the user, you use
> int(input("Question!")). However, what if the user wasn't that savvy 
> and
> didn't realize he/she HAD to enter a number?

It's considered good UI design to phrase the prompt in such a way as 
to
help the user know what to input:

Thus:

>>> x = int(input("Date(1-31): "))

or

>>> s = int(input("Sex(m=1,f=2): "))

And then you have trhe responsibility to catch the error just in 
case...

This is all part of "industrial standard" programming. You have to 
make
your programs foolproof, while bearing in mind that nature keeps 
buiding
bigger and better fools!


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list