Re: [Tutor] Simple variable type question

2010-02-06 Thread Antonio de la Fuente
* 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

Re: [Tutor] Simple variable type question

2010-02-05 Thread Alan Gauld
"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

Re: [Tutor] Simple variable type question

2010-02-05 Thread Sander Sweers
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

Re: [Tutor] Simple variable type question

2010-02-05 Thread ALAN GAULD
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

Re: [Tutor] Simple variable type question

2010-02-05 Thread Luke Paireepinart
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

Re: [Tutor] Simple variable type question

2010-02-05 Thread Alan Gauld
"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

Re: [Tutor] Simple variable type question

2010-02-05 Thread Luke Paireepinart
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

Re: [Tutor] Simple variable type question

2010-02-05 Thread Sander Sweers
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

Re: [Tutor] Simple variable type question

2010-02-05 Thread Wayne Werner
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

[Tutor] Simple variable type question

2010-02-05 Thread Antonio de la Fuente
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