Home CPSC 110

Trip Estimator

Due: February 15

Objective

To gain experience writing programs in Python including the use of input, output, variables, math and conditions.

Task

For this program, you will write a program that calculates how long it should take to get from point A to point B. This would be useful if you wanted to know whether you had time to walk to your favorite restaurant or coffee shop or whether you should settle for something closer.

For example, the distance between UMW and Hyperion coffee downtown is 0.9 miles. If you're walking quickly you can walk 4 miles per hour. (Or you might walk at a more leisurely pace of 3 miles per hour. Or you might want to run to mix your cardio with your snack run.)

The laws of physics tell us:

$Speed = \frac{Distance}{Time}$

$Distance = Speed \times Time$

$Time = \frac{Distance}{Speed}$

So if I need to travel the 0.9 miles at a speed of 4 miles per hour, it will take me approximately 13.5 minutes to arrive.

If I walk at a more leisurely pace, my speed will be 3 miles per hour. This would give me an estimated travel time of 18 minutes.

If I drive the same route, I might travel an average of 25 miles per hour and it will take me 2.16 minutes to arrive.

Your program should ask the user for the distance they need to travel, and also what speed they will be travelling at. It should then tell them the approximate travel time based on those things.

This same type of calculation is used in Google Maps when you calculate driving time for directions!


Details

Your program should do the following things:

  1. Welcome the user to the program and state the purpose of the program.
  2. Ask the user to enter the distance they will be travelling. Make the prompt clear and tell them what units to enter.
  3. Check if the distance they enter is 0 or a negative number. If it is, ask them to enter it again. (You don't need to handle the case when they put a negative in twice).
  4. Repeat steps 2 and 3 for the speed they walk at.
  5. Use arithmetic expressions to calculate the amount of travel time required. Be sure that the answer is expressed in minutes, not hours.
  6. Communicates the result to the user along with a clear label.

General Requirements

When writing your program, also be sure to:


Submitting

To submit your program, email the program file to ifinlay@umw.edu.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.