Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions