you have to write a Python function named horizontalHit that has 3 input parameters:
The first one is d1, which tells the distance from the left end of the pool to the stage.
The second one is d2, which tells the distance from the right end of the pool to the stage.
The third one is h, which tells the height of the stage.
Based on our physics knowledge, we know that we can only get the time first so we can get the velocity later. To calculate how long it takes to hit the pig, here is the formula:
h =v0*t + 0.5*g*t^2
where v0 is the vertical velocity of the bird. Assume that the bird is flying horizontally, and hence its vertical velocity is 0. Thus, we will use the following formula:
h = 0.5*g*t^2.
t = sqrt(2h/g)
Here g is the gravitational constant, which has a value of 9.8.
To get the velocity, we know that distance = v * t. Also, here, since the pig is in the middle of the pool, we need to use the following formula:
v = (d1+d2)/(2t)
Finally, after you get the time and the velocity, print them out in the function.
HERE IS MY CODE I STARTED and I DONT NO WHERE I AM GOING WRONG?
def horizontalHit(d1,d2,h):
g=9.8
h=0.5*g*(t^2)
t=math.sqrt((2*h)/g)
v=(d1+d2)/2
d=v*t
print("")
This post has been edited by modi123_1: 13 September 2012 - 09:36 PM
Reason for edit:: highlight your text and click the 'code' button in the editor bar.

New Topic/Question
Reply



MultiQuote





|