Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('{:.2f} {:.2f} {:.2f}'.format(your_value1, your_value2, your_value3)) python

Respuesta :

Answer:

See explaination

Explanation:

// Include the required header files.

#include <iostream>

// Include iomanip header file for setprecision().

#include <iomanip>

using namespace std;

// Start of the main() function.

int main() {

// Declare the double type variables for car's miles/gallon

// and gas dollar/gallon as milesPerGallon and

// dollarPerGallon, respectively.

double milesPerGallon, dollarPerGallon;

// Declare and initialize double type variable to hold

// the cost of

double costPerMile=0.0;

// Prompt the user to enter car's miles/gallon and

// gas dollars/gallon value.

cin >> milesPerGallon >> dollarPerGallon;

// Divide dollarPerGallon by milesPerGallon to

// compute the cost of travelling one mile.

costPerMile=dollarPerGallon/milesPerGallon;

// Use setprecision(2) function to display only two

// digits after the decimal point.

cout << fixed << setprecision(2);

// Display the cost per mile for 20 miles, 75 miles,

// and 500 miles, respectively.

cout << 20*costPerMile << " " << 75*costPerMile << " " << 500*costPerMile;

// Return 0 to the main() function.

return 0;

// End of the main() function.

}

Answer:

def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):

  gallon_used = driven_miles / miles_per_gallon

  cost = gallon_used * dollars_per_gallon  

  return cost  

miles_per_gallon = float(input(""))

dollars_per_gallon = float(input(""))

cost1 = driving_cost(10, miles_per_gallon, dollars_per_gallon)

cost2 = driving_cost(50, miles_per_gallon, dollars_per_gallon)

cost3 = driving_cost(400, miles_per_gallon, dollars_per_gallon)

print("%.2f" % cost1)

print("%.2f" % cost2)

print("%.2f" % cost3)

Explanation: