[Tutor] very odd math problem

Alex Hall mehgcap at gmail.com
Fri Mar 11 04:23:54 CET 2011


Hi all,
I am trying to get a list of ordered pairs from the below function. In
my code, evaluate is more exciting, but the evaluate here will at
least let this run. The below runs fine, with one exception: somehow,
it is saying that -2+2.0 is 4.x, where x is a huge decimal involving
E-16 (in other words, a really tiny number). Does anyone have any idea
what is going on here?

def getCoords(f, e1, e2, step=.1):
 #returns a list of (x,y) tuples from e1 to e2 at the given accuracy (step)
 time=0
 i=0
 coords=[]
 while time<=e2:
  print "time="+str(e1)+"+"+str(i)+"="
  time=e1+i
  print time #watch this line when above is -2+2.0
  coords.append((time, evaluate(f, time)))
  i=i+1*step
 return coords

def evaluate(x,y): return x*y
-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list