Apr 16, 2025 | 273 words | 3 min read
1.2.1. Road Trip#
Instructions#
You are planning a road trip with some friends. Before you go, you would like to estimate how much money you will need to budget for fuel. You know that you can use the following formula to estimate the round trip fuel cost:
where \(\text{cost}\) is the round trip cost of fuel, \(\text{distance}\) is the distance in miles between your starting point and your destination, \(\text{price}\) is the average price of fuel in dollars per gallon, and \(\text{mpg}\) is your vehicle’s fuel efficiency in miles per gallon.
Write a program that estimates the round trip fuel cost for you. Your program should ask the user to input the following:
the distance traveled, in miles
the average price of fuel in dollars per gallon
the fuel efficiency of your vehicle in miles per gallon
Once the input data has been entered, your program should calculate and display the estimated total cost of fuel. Since this is just a rough estimate, we will round the result down to the nearest whole dollar (e.g. if the estimated cost is \(\$33.57\), your program’s output should be \(\$33\)).
Sample Output#
Use the values in Table 1.1 below to test your program.
Case |
\(\text{distance} \ (\unit{\mile})\) |
\(\text{price} \ (\unit{\$\per\gallon})\) |
\(\text{mpg} \ (\unit{\mile\per\gallon})\) |
---|---|---|---|
1 |
811 |
4.273 |
19.2 |
2 |
1719 |
4.353 |
38.5 |
3 |
1265 |
3.851 |
21.4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 road_trip_login.py Road trip fuel cost estimator: How far away is your destination (miles)? 811 What is the average price of gas (dollars per gallon)? 4.273 What is the fuel efficiency of your vehicle (mpg)? 19.2
The fuel cost for this trip is approximately $360.
Case 2 Sample Output
$ python3 road_trip_login.py Road trip fuel cost estimator: How far away is your destination (miles)? 1719 What is the average price of gas (dollars per gallon)? 4.353 What is the fuel efficiency of your vehicle (mpg)? 38.5
The fuel cost for this trip is approximately $388.
Case 3 Sample Output
$ python3 road_trip_login.py Road trip fuel cost estimator: How far away is your destination (miles)? 1265 What is the average price of gas (dollars per gallon)? 3.851 What is the fuel efficiency of your vehicle (mpg)? 21.4
The fuel cost for this trip is approximately $455.
Deliverables#
Save your finished program as road_trip_login.py
, replacing
login
with your Purdue login. Then submit it along with all the
deliverables listed in
Table 1.2 below.
Deliverable |
Description |
---|---|
|
Your finished program. |
Screenshot(s) |
PNG(s) capturing all 3 test cases. |