0

I want to calculate a car's acceleration in mph. The initial velocity is 0, the final velocity is 60 and the time is meant to be inputted by the user in seconds. I know the equation for acceleration is (final velocity - initial velocity)/time.

However, I'm not sure how to get it into mph and how my equation needs to be modified. Here's my code so far:

time = 0
acceleration = 0
initial_velocity = 0
final_velocity = 60
print('Inputt the time required for the care to reach 60 mph in seconds.')
time = float(input())
acceleration = (final_velocity - initial_velocity)/time
print('The acceleration of the car is:' acceleration')
cottontail
  • 10,268
  • 18
  • 50
  • 51
Ann
  • 11
  • 2

3 Answers3

0

In Python 3, the input() function always returns a string.

You will need to parse it to a number - in your case, a floating point number, parsed with float() is what you need:

time = float(input())
AKX
  • 152,115
  • 15
  • 115
  • 172
0

According to python doc, inputs converts user input to a string, so you need to convert it to a numeric type first.

Also, to obtain a real result you must first convert time to hours or final_velocity to mps.

To implement the first option, you could add:

timeInHours = time/3600.0
acceleration = (final_velocity - initial_velocity)/timeInHours
Torkin
  • 1
  • 1
0

python input take input in string form, so you have to convert it into a float or at least

time = float(input())
time = int(input())

and also there two error in your last line

  1. Misplaced backquote (`) after acceleration
  2. In print string and variable should be separated with comma (,).
print('The acceleration of the car is:', acceleration)
Md Zafar Hassan
  • 284
  • 3
  • 13