[Tutor] Math Function and Python

Alan Gauld alan.gauld at btinternet.com
Mon Jul 2 09:37:18 CEST 2012


On 02/07/12 05:21, Greg Nielsen wrote:

> models the acceleration of the object. Y is the acceleration and X is
> the current speed of the object.
> Y = -.01X^2 * 1.45X

That's not the same as the formula you have implemented.

> it doesn't work. It's also in bold, so you can see it easily.
>          if keys[pygame.K_UP] and self.dy < (15 + self.speedMod):
>              if self.dy <= 0:
>                  /self.accelPoints += self.accelList[0]/
>                  *#self.dy += 1*
>              else:
>                  /self.accelPoints += self.accelList[self.dy]/
>                  *#self.accelPoints += ((-.1 * (self.dy * self.dy)) + (1.45 * self.dy))*

Are you sure the else is being executed?
Have you tried inserting a print statement to check the value right 
after the block?

> I did a test, and for some reason, it seems like the output of the
> function is never saved into the self.accelPoints variable, because it
> always prints out as 0.

If your dy is very close to zero the value of your formula will be very 
close to zero so accelPoints never increases. But you also commented out 
the dy increment line so dy never increases which migfht suggest the 
else never gets called??

Can you send us the actual code that fails rather than something else 
that nearly works?
Its much easier to debug the thing that's actually broken that something 
that looks vaguely like it.


> outputs a double, but even when i make accelPoints a double (made it
> equal 0.01 instead of 0) it still didn't work.

Provided they are both numbers Python will adapt. That's not likely to 
be the problem.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list