Re: [Tutor] Convert String to Int

2009-01-19 Thread Kent Johnson
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

Re: [Tutor] Convert String to Int

2009-01-19 Thread wesley chun
> 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 '

Re: [Tutor] Convert String to Int

2009-01-19 Thread Alan Gauld
"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 _

Re: [Tutor] Convert String to Int

2009-01-19 Thread Alan Gauld
"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

Re: [Tutor] Convert String to Int

2009-01-19 Thread Alan Gauld
"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

Re: [Tutor] Convert String to Int

2009-01-19 Thread spir
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

Re: [Tutor] Convert String to Int

2009-01-18 Thread bob gailer
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

Re: [Tutor] Convert String to Int

2009-01-18 Thread Ian Egland
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

Re: [Tutor] Convert String to Int

2009-01-18 Thread Marc Tompkins
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

Re: [Tutor] Convert String to Int

2009-01-18 Thread Sridhar Ratnakumar
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

[Tutor] Convert String to Int

2009-01-18 Thread Ian Egland
'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