Stopping Distance Calculator

road-sign-deerIn this challenge, we will write a Python program to estimate the total stopping distance of a vehicle based on its speed. The stopping distance consists of two components. The first component is the reaction distance covered by the vehicle due to the reaction time/delay of the driver between the moment an obstacle is spotted on the road and the moment the brakes are applied. The second component is the braking distance which is the distance a vehicle will travel from the point when its brakes are fully applied to when it comes to a complete stop. The braking distance is primarily affected by the original speed of the vehicle and the coefficient of friction between the tires and the road surface.

Based on the law of physics, we can write the stopping distance formula as follows:
stopping-distance-formula

For this challenge we will use a response time (tr) of 1.5 seconds, the average response time of a driver. In reality this response time varies depending on the age of the driver, their experience and their condition: e.g. A tired driver will have a slower response time than an alert driver.

The common baseline value for the friction coefficient µ (pronounced mu) is 0.7. In reality this coefficient varies depending on the condition of the road (e.g. dry/wet/icy) as well as the types, condition and pressure of the tyres.

Our aim is to write a Python program based on the INPUT / PROCESS / OUTPUT model that will:

  1. INPUT: Ask the user to enter the speed of a car in mph (Miles per hour)
  2. PROCESS: Convert this speed in mps (meters per second)
  3. PROCESS: Apply the stopping distance formula (using µ = 0.7 and tr = 1.5s)
  4. OUTPUT: Display the estimated stopping distance of the car in meters.

Speed Conversion Formula


To convert the speed of the vehicle from mph (miles per hour) to mps (meter per second) you will need to apply the following formula:
speed-conversion-formula

Complete the Python Code


Testing


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values Expected Output Actual Output
#1 50 mph 70 meters
#2 70 mph 118 meters
#3 30 mph 33 meters

Extension Task:


The value of the friction coefficient µ depends on the condition of the road.

Adapt your script to ask the user if the road is dry, wet, or icy.
Based on the user input, you will use the following friction coefficients:

Road Condition Friction Coefficient
Dry µ = 0.7
Wet µ = 0.5
Icy µ = 0.3

Testing


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values Expected Output Actual Output
#1 30 mph, Dry Road 33 meters
#2 30 mph, Wet Road 38 meters
#3 30 mph, Icy Road 51 meters
#4 70 mph, Dry Road 118 meters
#5 70 mph, Wet Road 146 meters
#6 70 mph. Icy Road 213 meters
Share Button
Tagged with: