Question: PYTHON 1. (expenses.py) According to its documentation, the 2021 MINI Cooper gets 28 mpg in the city and 38 mpg on the highway. Write a
PYTHON


1. (expenses.py) According to its documentation, the 2021 MINI Cooper gets 28 mpg in the city and 38 mpg on the highway. Write a program to compute the total cost of gasoline used during your most recent trip. In main(), prompt the user for two floats: a) total miles driven and b) percentage of total miles driven on a highway. Be sure to validate user input: total miles driven should be positive, and percentage spent in highway driving should be a value between 0 and 100. main() should prompt the user for new trip data until user is done. main () is also responsible for displaying the trip information. You must use the following two user-defined functions: Function Name total_gallons Output The gas consumption Input Processing total miles, highway percentage Computes the total gas consumption (gallons) according to this formula below. Uses two CONSTANTS, one each for city and highway mpg. total_highway_miles total_city_miles total_gas_consumption = MPG HWY MPG CITY + Function Name gas_expense Input total gallons Output The total spent on gas Processing Computes the total spent on gasoline for this trip. Use a CONSTANT price of 2.29 per gallon Sample Run #1 Computing your gasoline expenses... Total miles driven: 367 Percentage of total miles driven on a highway: 50 Here is the information for your trip: Total miles: 367.0 Gas consumption: 11.4 gal Total cost: $ 26.07 Compute gas expense for another trip (y or n)? n Sample Run #2 Computing your gasoline expenses... Total miles driven: -5 Enter a value > 0: 5 Percentage of total miles driven on a highway: 20 Here is the information for your trip: Total miles: 5.0 Gas consumption: 0.2 gal Total cost: $ 0.39 Compute gas expense for another trip (y or n)? y Total miles driven: 1080 Percentage of total miles driven on a highway: 80 Here is the information for your trip: Total miles: 1080.0 Gas consumption: 30.5 gal Total cost: $ 69.73 Compute gas expense for another trip (y or n)? n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
