* Antonio de la Fuente [2010-02-05 16:54:59 +]:
> Date: Fri, 5 Feb 2010 16:54:59 +
> From: Antonio de la Fuente
> To: Python Tutor mailing list
> Subject: [Tutor] Simple variable type question
> Organization: (muybien.org)
> User-Agent: Mutt/1.5.20 (2009-0
"Sander Sweers" wrote
On vr, 2010-02-05 at 20:39 +, ALAN GAULD wrote:
return float(x1-y1)/(x2-y2)
Does not work properly in version 2. Example is the 3rd doc test:
float((3-2)/(3-1)) gives 0.0 instead of 0.5.
That's what I did wrong dfirst time round, I had the parens round
the who
On vr, 2010-02-05 at 20:39 +, ALAN GAULD wrote:
> return float(x1-y1)/(x2-y2)
Does not work properly in version 2. Example is the 3rd doc test:
float((3-2)/(3-1)) gives 0.0 instead of 0.5.
Greets
Sander
___
Tutor maillist - Tutor@python.org
To u
Or just
return float(y2-y1/x2-x1)
>>
>>
>Alan why are you suggesting this, surely this will cause the decimal values to
>be truncated? Or does this somehow work differently in Python 3?
>
It would work different in v3 because / is no longer interger division.
However, I just
On Fri, Feb 5, 2010 at 12:45 PM, Alan Gauld wrote:
>
> "Antonio de la Fuente" wrote
>
>> the doctest for the slope function failed, because is expecting a
>>
>> floating point value and not an integer:
>>
>
> So convert it to a float.
>
> Or just
> return float(y2-y1/x2-x1)
>
> Alan why are y
"Antonio de la Fuente" wrote
the doctest for the slope function failed, because is expecting a
floating point value and not an integer:
So convert it to a float.
def slope(x1, y1, x2, y2):
result_slope = ((y2 - y1) / (x2 - x1)) * 1.0
return result_slope
return float(result
You want to promote one of your variables to float before you do the
calculation, this will make all other variables automatically cast. So
(float(y2) - y1) / (x2-x1). if you do the float cast after the
calculation, you will do the calculation as integers and so even
though you'll get "2.0" you wo
On vr, 2010-02-05 at 16:54 +, Antonio de la Fuente wrote:
> http://openbookproject.net/thinkcs/python/english2e/ch05.html
>
> exercise number 3 (slope function) and when I run it:
>
> python ch05.py -v
>
> the doctest for the slope function failed, because is expecting a
> floating point val
On Fri, Feb 5, 2010 at 10:54 AM, Antonio de la Fuente wrote:
> Hi all,
>
> I'm trying to do exercises from:
>
> http://openbookproject.net/thinkcs/python/english2e/ch05.html
>
> exercise number 3 (slope function) and when I run it:
>
> python ch05.py -v
>
> the doctest for the slope function faile
Hi all,
I'm trying to do exercises from:
http://openbookproject.net/thinkcs/python/english2e/ch05.html
exercise number 3 (slope function) and when I run it:
python ch05.py -v
the doctest for the slope function failed, because is expecting a
floating point value and not an integer:
Failed exam
10 matches
Mail list logo