Question: Let's update our Modularize version of Compound Interest Python Program, FuelCostModularized.py , however we will create a List of fuel trips miles(m) from input, and

Let's update our Modularize version of Compound Interest Python Program, FuelCostModularized.py, however we will create a List of fuel trips miles(m) from input, and Tuple for Octane values of literal constants: submit FuelCostList.py.

See updates in blue.

Fuel Costs

We can estimate the cost of fuel for a Road Trip with a given number of inputs. If we know total miles our Road trip (m), how many miles per gallon our vehicle gets (mpg) and the fuel cost per gallon(CPG), we can estimate total costs for fuel required complete our road trip from point A to point B.

FuelCost = m/mpg * cpg

Where, the terms in the formula are:

m is total miles of the road trip MPG is miles per gallon of vehicle - which is now a NAMED CONSTANT holding the value 25.00 cpg is the cost per gallon for fuel, set in our Selection Structure contained within our calcCpg(Octane) module

In our program logic, cpg is set by the following Selection Structure: Unleaded gas up to 89.00 Octane -> $6.00 per gallon Unleaded gas over 89.01 - 90.99 Octane -> $8.00 per gallon Unleaded gas over 91.00 - 94.99 Octane -> $10.45 per gallon High Octane racing fuel, 95.00 - 120.00 Octane -> 23.94 per gallon High Octane jet fuel, anything above 120 Octane -> 36.98 per gallon

re-use

The modules we created 2 weeks ago

calcCpg(Octane)

calcFuelCost(m,mpg,cpg)

Write a Python program that

creates a Tuple for immutable collection of Octane values ---> Octane = (89.00, 89.01, 90.99, 91.00, 94.99, 95.00, 120.00 )

MPG is now a named constant with the value of 25.00

create a List for miles (m) values gathered from input

takes input: Use a counter loop (for loop) to create a List of values for m, get input for 7 values for m (refer to pg. 180 and Program 4-7) and add them to a List.

Processing:

use the List sort method to sort the List of m , from lowest to highest m.

Process the List of m (refer to section 7.7) us a for-loop to access each element of your List of m and corresponding element in our Tuple, pass these values - along with your named constant value for MPG - to your modules to calculate the Fuel Costs for the 5 trips.

Output: to the terminal, Total miles of road trip, mpg, cpg, Octane and calculated Fuel Costs. *be sure to format your output to 2 decimal places.....

Psuedocode: MPG = 25.00 Octane = (89.00, 89.01, 90.99, 91.00, 94.99, 120.00, 125.00) for i in range 1 to 7: input m. add m to mList[] end. mList.sort() for i in range(len(mList)): cpg = calcCpg(Octane[i]) totalFuelCost = calcFuelCost(mList[i],MPG,cpg) output "A trip of " + mList[i] + " at " + MPG + " miles per gallon at a cost of " + cpg + " per gallon of Octane " + Octane + " will Round up to a total cost of Fuel at $" + totalFuelCost end. output "End of Program"

[0 points] re-submit Fuel.py (contains our modules) so I can run this weeks submission

[18 points] submit FuelCostList.py

[2 points] Write in text box the similarities and differences of Lists vs. Tuples, be sure to explain the term "mutable" and "immutable"

Current Code from FuelCostModularized

#FuelCostModularized.py def calculate_fuel_cost(m, mpg, octane): if octane <= 89.00: cpg = 6.00 elif octane <= 90.99: cpg = 8.00 elif octane <= 94.99: cpg = 10.45 elif octane <= 120.00: cpg = 23.94 elif octane > 120: cpg = 36.98 fuel_cost = m/mpg * cpg return fuel_cost m = float(input("Enter the total miles of the road trip: ")) while m != 0: mpg = float(input("Enter the miles per gallon of the vehicle: ")) octane = float(input("Enter the octane level: ")) fuel_cost = fuel_cost(m, mpg, octane) print("Total miles of road trip: {:.2f}".format(m)) print("Miles per gallon of vehicle: {:.2f}".format(mpg)) print("Cost per gallon of fuel: ${:.2f}".format(fuel_cost/m*mpg)) print("Octane level: {:.2f}".format(octane)) print("Fuel cost for the trip: ${:.2f}".format(fuel_cost)) m = float(input("Enter the total miles of the road trip: "))

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 Databases Questions!