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
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
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
> 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
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
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
> 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 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()
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
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
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
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
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
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:
>
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."
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
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("
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
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
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
20 matches
Mail list logo