Answered step by step
Verified Expert Solution
Link Copied!

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
1. def efficiency(dist, gas)
2. return dist/gas
3. km = input ("How far did your car travel? (In kilometers?))
4. liters = input ("How much gas did you use? (In liters)"
5. MPG = efficiency(dist_traveled, Liters)
6. 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

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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions