I just started learning python last week and I have a homework assignment that wants me to design code that outputs the correct answer to this problem:
A cyclist peddling on a level road increases from 3 mph to 15 mph in 0.5 hours.
The equation below can be used to determine the rate of acceleration, where A is acceleration, t is time interval in hours, iV is initial velocity, and fV is final velocity.
A = (fV – iV)/t
Determine the rate of acceleration for the cyclist (in miles/hr^2) assuming that the cyclist continues to accelerate a constant rate for the first 0.5 hours.
Now at first, I had no idea how to go at this problem, but then I put in values in the equation and got A = (15 - 3)/0.5 = 24
I'm not sure what the units to 24 are, I think they're miles per minute or something. I know I have some unit conversion issue, but for now this slightly incorrect math interpretation is what i'm working with.
My code is as follows:
def main():
InitialVelocity = 15
FinalVelocity = 3
TimeIntervalInHours = 0.5
RateofAcceleration = (FinalVelocity-InitialVelocity)/TimeIntervalInHours
print(RateofAcceleration)
This prints nothing.
Another code I developed is as follows:
InitialVelocity = 15
FinalVelocity = 3
TimeIntervalInHours = 0.5
NewVelocity = FinalVelocity - InitialVelocity
RateofAcceleration = NewVelocity/TimeIntervalInHours
print(RateofAcceleration)
Error message:
SyntaxError: multiple statements found while compiling a single statement
What can I do to change my code to correctly model this math problem and output the answer?