Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In computer programming there are three kinds of errors: syntax errors, runtime errors, and logic errors. The code fragment below is meant to calculate a
In computer programming there are three kinds of errors: syntax errors, runtime errors, and
logic errors. The code fragment below is meant to calculate a cars fuel economy after reading
in the distance travelled and amount of petrol used. The fuel economy is calculated by the
following formula: kmPerLitre kilometers litres. The code fragment contains syntax, logic
and potential runtime errors. Identify and correct at least five errors in the
def efficiencydist gas
return distgas
km input How far did your car travel? In kilometers?
liters input How much gas did you use? In liters
MPG efficiencydisttraveled, Liters
print MPG
Please note that the line numbers are not part of the code. Assuming that users will only
provide valid inputs, find at least three syntax errors, one runtime error, and one logical error
in the above code.
For each of these errors, state the number of the line on which it occurs and how it should be
corrected.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started