On Mon, Jan 19, 2009 at 1:36 PM, wesley chun wrote:
>> if type(x) == int: # check its an integer
>
>
> i also understand that it's "isinstance(x, int)" should be used
> instead of the above or "if type(x) is int" but i'm running a blank as
> to why at this exact moment... perhaps it's an all-C f
> if type(x) == int: # check its an integer
i also understand that it's "isinstance(x, int)" should be used
instead of the above or "if type(x) is int" but i'm running a blank as
to why at this exact moment... perhaps it's an all-C function?
however, all of these comparisons are only good if '
"bob gailer" wrote
a = raw_input("Enter an integer:")
if a.isdigit():
# process input
Oops, yes. My posting on this is wrong because you can't
compare to int untl after you convert the value. isdigit()
is the correct check.
Apologies - too early in the morning...
Alan G
_
"Ian Egland" wrote
Actually, nobody told me how to catch it before it occurs
x = input('x = ')
if type(x) == int: # check its an integer
x = int(x)# ok, so convert to a number
else:
print ("Please enter a number")
But that leads to much more complex and inefficient code
so we
"Ian Egland" 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
Le Sun, 18 Jan 2009 21:59:04 -0500,
bob gailer a écrit :
> Ian Egland wrote:
> > 'Allo All.
> >
> > 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? Pro
Ian Egland wrote:
'Allo All.
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? Program crash. Is
there a way that I can get the input as a string, check and se
Actually, nobody told me how to catch it before it occurs, though this
"after error" stuff is new to me.
Could you send an example of how to catch it beforehand? Just for the
record?
Thanks.
Ian
On Sun, Jan 18, 2009 at 8:35 PM, Marc Tompkins wrote:
> On Sun, Jan 18, 2009 at 5:15 PM, Ian Egland
On Sun, Jan 18, 2009 at 5:15 PM, Ian Egland 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? Program crash. Is there a way
> that I can get the input
On Sun, Jan 18, 2009 at 5:15 PM, Ian Egland 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? Program crash. Is there a way
> that I can get the input
'Allo All.
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? Program crash. Is there a way
that I can get the input as a string, check and see if it's convertible t
11 matches
Mail list logo