Describe three common errors that cause a program to work incorrectly.
What will be an ideal response?
When a program doesn't work correctly, it is usually the result of a syntax, runtime, or logic error.
Syntax errors. A syntax error occurs when an instruction does not follow the syntax rules, or grammar, of the programming language. For example, leaving off the colon in the statement while (loopCount <= 3): would produce a syntax error because the colon is required to set off the loop control from the statements that are executed within the loop. Syntax errors are easy to make, but they are usually also easy to detect and correct.
Runtime errors. An error that is detected as a program runs is referred to as a runtime error. Some runtime errors result from instructions that the computer can't execute. The Python instruction loopCount = heelClicks/0 produces a runtime error because dividing by 0 is a mathematically impossible operation that the computer cannot perform.
Logic errors. A logic error is a type of runtime error that is caused by a fault in the logic or design of a program. In the Wizard of Oz code, using while (loopCount < 3): would produce a logic error because the program would print ‘There's no place like home.' only two times instead of three times. The correct code (loopCount <= 3): differs from the incorrect code by the addition of an = symbol. Logic errors can be caused by an inadequate definition of the problem or an incorrect formula for a calculation, and are usually more difficult to identify than syntax errors.
You might also like to view...
The getNext function was inlined because:
A. it is likely to be used in a loop, so using it will be faster while not using too much memory for code B. the next element to get is in line with the previous element C. we need many copies of the getNext function, since there are many elements to retrieve D. searches are always faster when they are made in a straight line through the list
A web page consists of ____ sections.
A. two B. three C. four D. six
Click Breaks in the Page Setup group to insert a section break
Indicate whether the statement is true or false
_______________ assistants on the latest smartphones and tablets enable quick, vocal interaction to accomplish common goals.
Fill in the blank(s) with the appropriate word(s).