Question: How can I change the below code? Miles Per Gallon Use input to prompt for float miles driven Keep promping for miles until the entry

How can I change the below code?

Miles Per Gallon

Use input to prompt for float miles driven Keep promping for miles until the entry is greater than 0

Use input to prompt for float gallons used Keep promping for gallons until the entry is greater than 0

Calculate miles per gallon as miles didived by gallons, rounded to 2 decimal places

Display miles, gallons and miles per gallon

Example

Input: (bold in computer prompt; other iis user response)

Enter miles: -500 Enter miles: 500 Enter gallons: 0 Enter gallons: 18 Display

Miles = 500.0 Gallons = 18.0 Miles Per Gallon = 27.78 Be sure to fill out author and date DO NOTwrite a new program Fix the current program

# input
isErrorGallon = True
isErrorMile = True
while isErrorMile:
try:
miles = float(input("Plesse enter miles driven: "))
if miles >= 0:
isErrorMile = False
except:
isErrorMile = True
while isErrorMile:
try:
gallons = float(input("Plesse enter gallons used: "))
if gallons >= 0:
isErrorGallon = False
except:
isErrorMile = True
# calculation
MPG = miles / gallons
# output
print("Miles =", miles, " Gallons =", gallons, " Miles Per Gallon=", MPG)

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!