Question: Exercise 3 - 1 Enhance the Miles Per Gallon program In this exercise, you ll enhance the Miles Per Gallon program in figure 3 -

Exercise 3-1 Enhance the Miles Per Gallon program
In this exercise, youll enhance the Miles Per Gallon program in figure 3-8 so the console display looks something like this:
The Miles Per Gallon program
Enter miles driven:150
Enter gallons of gas used:15.2
Enter cost per gallon:4.25
Miles Per Gallon:9.87
Total Gas Cost:64.6
Cost Per Mile:0.4
Get entries for another trip (y/n)? y
Enter miles driven:225
Enter gallons of gas used:16
Enter cost per gallon:4.25
Miles Per Gallon:14.06
Total Gas Cost:68.0
Cost Per Mile:0.3
Get entries for another trip (y/n)?
1. Start IDLE and open the mpg.py file thats in this folder: murach/python/exercises/ch03
2. Test the program with valid and invalid values.
3. Enhance the program so it lets the user repeat the entries and get the miles per gallon for more than one trip. To do that, use a while loop.
4. Modify this program so it gets the cost of a gallon of gas as another entry from the user, and validate this entry before using it in your calculations. If all three entries are valid, calculate the total gas cost and the cost per mile, and display the results on the console.
When you completed modifications shown above, then enhance your program so the console will look something like this:
The Miles Per Gallon program
Enter miles driven:150
Enter gallons of gas used:15.2
Enter cost per gallon:4.25
Miles Per Gallon:9.87
Total Gas Cost:64.6
Cost Per Mile:0.4
Get entries for another trip (y/n)? y
Enter miles driven:225
Enter gallons of gas used:16
Enter cost per gallon:4.25
Miles Per Gallon:14.06
Total Gas Cost:68.0
Cost Per Mile:0.3
Get entries for another trip (y/n)? n
Summary for 2 trips:
Total Miles Driven:375.0
Total Gallons Used:31.2
Total Gas Cost:132.6
Average Miles Per Gallon: 12.0
Thank you for using miles per gallon program! Bye.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!