Re: [Tutor] exceptions problem

2010-09-13 Thread Francesco Loffredo
First, *THANK YOU!* for your clear and thorough explaination, Steven. On 13/09/2010 13.59, Steven D'Aprano wrote: On Mon, 13 Sep 2010 08:55:46 pm Francesco Loffredo wrote: I don't like this rough behaviour of int(), spitting out an exception if given a legitimate string representation of a floa

Re: [Tutor] exceptions problem

2010-09-13 Thread Steven D'Aprano
On Mon, 13 Sep 2010 08:55:46 pm Francesco Loffredo wrote: > I don't like this rough behaviour of int(), spitting out an > exception if given a legitimate string representation of a float. Can > some of you Tutors explain me why it must be so? The int() function behaves as a constructor, producing

Re: [Tutor] exceptions problem

2010-09-13 Thread Francesco Loffredo
On 11/09/2010 20.43, bob gailer wrote: On 9/11/2010 12:12 PM, Roelof Wobben wrote: ... You can't. I made that comment in the context of the OPs function: def readposint(): x = raw_input("Please enter a positive integer :") try: if (int(x)<0 or (float(x) - int(x)> 0)): raise(ValueError) except

[Tutor] exceptions problem

2010-09-11 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: bgai...@gmail.com > Subject: RE: [Tutor] exceptions problem > Date: Sat, 11 Sep 2010 18:51:12 + > > > > > >> Date: Sat, 11 Sep 2010 14:43:28

Re: [Tutor] exceptions problem

2010-09-11 Thread bob gailer
On 9/11/2010 12:12 PM, Roelof Wobben wrote: Date: Sat, 11 Sep 2010 11:05:54 -0400 From: bgai...@gmail.com To: tutor@python.org Subject: Re: [Tutor] exceptions problem On 9/11/2010 6:56 AM, Peter Otten wrote: Steven D'Aprano wrote: On Sat, 1

Re: [Tutor] exceptions problem

2010-09-11 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: Hello Bob, Oke, I try to fish. When I do x="a" y=nt(x) Then I get ValueError. When I do x= 1.2 y=int(x) No exception is raised. But when I do then x = I get a false. When I now do float(x) - int(x) I get 1.2 - 1 =.2 and that's greater then 0 Because one

Re: [Tutor] exceptions problem

2010-09-11 Thread Roelof Wobben
> Date: Sat, 11 Sep 2010 11:05:54 -0400 > From: bgai...@gmail.com > To: tutor@python.org > Subject: Re: [Tutor] exceptions problem > > On 9/11/2010 6:56 AM, Peter Otten wrote: >> Steven D'Aprano wrote: >> >>>

Re: [Tutor] exceptions problem

2010-09-11 Thread bob gailer
On 9/11/2010 6:56 AM, Peter Otten wrote: Steven D'Aprano wrote: On Sat, 11 Sep 2010 09:56:41 am bob gailer wrote: I never thought that you can use a float and a integer to look if the number is a integer. You can't. I made that comment in the context of the OPs function: def readposint()

Re: [Tutor] exceptions problem

2010-09-11 Thread Peter Otten
Steven D'Aprano wrote: > On Sat, 11 Sep 2010 09:56:41 am bob gailer wrote: >> > I never thought that you can use a float and a integer to look if >> > the number is a integer. >> >> You can't. > > What? Of course you can. > > def is_integer(x): > """Return True if x is an integer.""" > t

Re: [Tutor] exceptions problem

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 09:56:41 am bob gailer wrote: > > I never thought that you can use a float and a integer to look if > > the number is a integer. > > You can't. What? Of course you can. def is_integer(x): """Return True if x is an integer.""" try: return 1.0*x == int(x) exc

Re: [Tutor] exceptions problem

2010-09-11 Thread Francesco Loffredo
On 11/09/2010 1.56, bob gailer wrote: On 9/10/2010 2:48 PM, Roelof Wobben wrote: Date: Fri, 10 Sep 2010 20:23:09 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem ... > ... > Roelof Francesco Thank you. I never thought that you can use a float

Re: [Tutor] exceptions problem

2010-09-10 Thread Luke Paireepinart
Sep 2010 20:23:09 +0200 > From: f...@libero.it > To: tutor@python.org > Subject: Re: [Tutor] exceptions problem > > On 10/09/2010 18.12, Roelof Wobben wrote: >> ... >> def readposint(): >> x = raw_input("Please enter a positive integer :") &g

Re: [Tutor] exceptions problem

2010-09-10 Thread bob gailer
On 9/10/2010 2:48 PM, Roelof Wobben wrote: Date: Fri, 10 Sep 2010 20:23:09 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem On 10/09/2010 18.12, Roelof Wobben wrote: > ... > def readposint(): > x = raw_input("Please enter a po

Re: [Tutor] exceptions problem

2010-09-10 Thread Roelof Wobben
Date: Fri, 10 Sep 2010 20:23:09 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem On 10/09/2010 18.12, Roelof Wobben wrote: > ... > def readposint(): > x = raw_input("Please enter a positive integer :") > try: >

Re: [Tutor] exceptions problem

2010-09-10 Thread Francesco Loffredo
On 10/09/2010 18.12, Roelof Wobben wrote: ... def readposint(): x = raw_input("Please enter a positive integer :") try: if not (x == int(x) and x< 0): raise(ValueError) except: print x , "is not a positive integer.Try again."

Re: [Tutor] exceptions problem

2010-09-10 Thread Roelof Wobben
From: rwob...@hotmail.com To: tutor@python.org Date: Fri, 10 Sep 2010 16:12:08 + Subject: Re: [Tutor] exceptions problem Date: Fri, 10 Sep 2010 18:07:13 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem Oops, I sent this to Roelof... Ok, I

Re: [Tutor] exceptions problem

2010-09-10 Thread Roelof Wobben
Date: Fri, 10 Sep 2010 18:07:13 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem Oops, I sent this to Roelof... Ok, I must amend it anyway... On 10/09/2010 17.13, Roelof Wobben wrote: > ... > def readposint(): > x = raw_input("

Re: [Tutor] exceptions problem

2010-09-10 Thread Francesco Loffredo
Oops, I sent this to Roelof... Ok, I must amend it anyway... On 10/09/2010 17.13, Roelof Wobben wrote: ... def readposint(): x = raw_input("Please enter a positive integer :") try: x = int(x) and x> 0 except: print x , "is not a positive i

Re: [Tutor] exceptions problem

2010-09-10 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: Now I thought this would work:def readposint(): x = raw_input("Please enter a positive integer :") try: x = int(x) and x> 0 except: print x , "is not a positive integer. Try again." return False return Truey = rea

[Tutor] exceptions problem

2010-09-10 Thread Roelof Wobben
Hello, I have this problem : Write a function named readposint that prompts the user for a positive integer and then checks the input to confirm that it meets the requirements. A sample session might look like this: >>> num = readposint() Please enter a positive integer: yes yes is not