Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are to write a program that will calculate and print to the screen the miles per gallon your car gets, the cost of fuel

You are to write a program that will calculate and print to the screen the miles per gallon your car gets, the cost of fuel per mile and the annual cost of fuel for that car.
Your program must ask the user to enter the following information, and save the values entered into variables (use the names below):
beginningOdometerReading. ## save as an int
endingOdometerReading. ## save as an int
gallonsToFillTank ## save as a float
costPerGallonOf Gas ## save as a float
numberMilesDrivenPerYear ## save as an int
Most cars calculate the average miles per gallon for you. Assume you have an old car that does not. You have to calculate that yourself. So you fill up the tank, record the odometer reading, drive around, fill up the tank, record the odometer reading and the number of gallons of fuel you had to put into the tank to fill it. You calculate the miles per gallon by subtracting the endingOdometerReading from the beginningOdometerReading and then dividing by gallonsToFillTank
Assume that the cost of fuel remains the same all year.
To format a number as currency to two decimal points the command is (assuming that cost is the value, a variable name or an actual value you want formatted and printed):
print('${:,.2f}'.format(cost))
Here is a sample input/output:
Please enter the beginning odometer reading:
10000
Please enter the ending odometer reading:
10500
Please enter the number of gallons to fill the tank:
10
Please enter the cost per gallon of fuel:
3.00
Please enter the number of miles driven per year:
15000
Average Miles Per Gallon: 50.00
Fuel Cost Per Mile: $0.06
Annual Cost of Fuel: $900.00
Remember how to get input from the user:
Getting an int:
beginning_odometer_reading= int(input("Please enter the beginning odometer reading:))
Getting a float:
cost_per_gallon_of_fuel = float(input("Please enter the cost of a gallon of fuel:))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago

Question

Understand how to design effective service guarantees.

Answered: 1 week ago

Question

Know when firms should not offer service guarantees.

Answered: 1 week ago