PrepGo

AP Computer Science Principles Practice Quiz: Identifying and Correcting Errors

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Test your understanding with short quizzes. This quiz has 16 questions to check your progress.

Question 1 of 16

A programmer forgets to add a semicolon at the end of a line of code, violating the programming language's rules. The program fails to run. What type of error is this?

All Questions (16)

A programmer forgets to add a semicolon at the end of a line of code, violating the programming language's rules. The program fails to run. What type of error is this?

A) Logic error

B) Syntax error

C) Run-time error

D) Overflow error

Correct Answer: B

According to the provided content, a syntax error is a mistake where the rules of the programming language are not followed. Forgetting a required semicolon is a direct violation of language rules.

An algorithm is designed to calculate the area of a rectangle (length * width), but the code was written to add the length and width instead. The program runs without crashing but produces the wrong answer. This is an example of a:

A) Logic error

B) Syntax error

C) Run-time error

D) Overflow error

Correct Answer: A

The content defines a logic error as a mistake in the algorithm that causes it to behave incorrectly or unexpectedly. The program runs, but the faulty algorithm produces an incorrect result, which is a classic logic error.

A program is designed to process user ages, which are expected to be between 0 and 120. Which set of defined inputs would be most effective for testing this program according to the provided guidelines?

A) 25, 50, 75

B) 0, 120, 121

C) A negative number, a letter, a symbol

D) 10, 20, 30

Correct Answer: B

The content states that defined inputs should demonstrate outcomes 'at or just beyond the extremes (minimum and maximum) of input data.' The inputs 0 (minimum), 120 (maximum), and 121 (just beyond the maximum) best fit this requirement.

A developer is unsure why a variable is changing its value unexpectedly. They add several `print()` statements to their code to display the variable's value at different stages of execution. Which error-finding method is being used?

A) Hand tracing

B) Using a debugger

C) Adding extra output statement(s)

D) Using visualizations

Correct Answer: C

The provided content lists 'adding extra output statement(s)' as an effective way to find and correct errors. Displaying a variable's value with a print statement is a direct example of this technique.

A program successfully starts, but halfway through its execution, it stops and displays a 'division by zero' message. This type of error, which occurs during the execution of a program, is best classified as a:

A) Logic error

B) Syntax error

C) Run-time error

D) Overflow error

Correct Answer: C

The content defines a run-time error as 'a mistake in the program that occurs during the execution of a program.' Since the error happened while the program was running, it is a run-time error.

A financial application is calculating the total assets of a large corporation. The final number is so large that it exceeds the maximum value the variable can hold, causing the stored value to become a seemingly random or incorrect number. This is known as an:

A) Overflow error

B) Syntax error

C) Run-time error

D) Logic error

Correct Answer: A

An overflow error is defined as an error that 'occurs when a computer attempts to handle a number that is outside of the defined range of values.' This scenario perfectly matches the definition.

Before a programmer can create a set of test cases with defined inputs, what must they first understand to ensure the tests are relevant and comprehensive?

A) The programming language's run-time errors

B) The program requirements

C) The most common syntax errors

D) How to use a debugger

Correct Answer: B

The content explicitly states that 'Program requirements are needed to identify appropriate defined inputs for testing.' Without knowing the requirements, a programmer cannot determine what the expected outcomes or extreme values are.

What is the primary goal of testing in the development process, according to the provided text?

A) To find every possible bug in the program

B) To ensure the program follows the language's syntax rules

C) To use defined inputs to ensure the program produces expected outcomes

D) To check for overflow errors exclusively

Correct Answer: C

The text states, 'In the development process, testing uses defined inputs to ensure that an algorithm or program is producing the expected outcomes.' This is the primary purpose of testing.

A programmer is debugging a complex loop. They create a table on paper and manually write down the value of each variable for each iteration of the loop to find a mistake. This technique is an example of:

A) Using a debugger

B) Using visualizations

C) Adding output statements

D) Hand tracing

Correct Answer: D

The provided content lists 'hand tracing' as an effective way to find and correct errors. This process involves manually stepping through the code and tracking variables, which is exactly what the programmer is doing.

A program is intended to give a discount to users with 10 or more loyalty points. A logic error causes the program to give the discount to users with MORE than 10 points, excluding those with exactly 10. Which input value would be essential for discovering this specific error?

A) 9

B) 10

C) 11

D) 0

Correct Answer: B

The content emphasizes testing at the 'extremes (minimum and maximum) of input data.' In this case, 10 is the minimum value for the expected outcome (getting a discount). Testing with the input 10 would reveal that the program is behaving incorrectly at this boundary condition.

Which of the following is NOT listed in the provided content as an effective way to find and correct errors?

A) Test cases

B) Hand tracing

C) Asking another programmer for help

D) Debuggers

Correct Answer: C

The content lists the following effective ways: 'test cases, hand tracing, visualizations, debuggers, adding extra output statement(s)'. Asking another programmer for help is not on this specific list.

After running a series of tests, a programmer finds that several outputs do not match the expected outcomes. According to the development process described, what is the programmer's next step?

A) Release the program as is

B) Delete the failing test cases

C) Use the results to revise the algorithm or program

D) Assume the computer has a hardware fault

Correct Answer: C

The text states, 'Programmers use the results from testing to revise their algorithms or programs.' This indicates that identifying an error through testing should lead to correcting it.

The process of identifying inputs and their corresponding expected outputs or behaviors is primarily used to:

A) Check the correctness of an algorithm or program

B) Choose a programming language

C) Prevent all run-time errors

D) Write the initial program requirements

Correct Answer: A

Point 2 of the provided content states that this process is used to 'check the correctness of an algorithm or program.' This is the fundamental basis of testing.

A program correctly handles all positive and negative numbers but crashes when the input is exactly zero. This crash occurs during program execution. This error is best described as a:

A) Syntax error because the program failed

B) Run-time error triggered by a specific input value

C) Logic error because the algorithm is flawed for all inputs

D) Overflow error because zero is outside the range

Correct Answer: B

The error occurs 'during the execution of a program,' which fits the definition of a run-time error. It is not a syntax error because the program started running. While it stems from a flaw in logic, its manifestation as a crash during execution makes 'run-time error' the most precise classification based on the provided definitions.

What is the general, two-step process for handling errors in an algorithm or program mentioned in the text?

A) Test the program and then document the results

B) Write the code and then compile it

C) Identify the error and then correct the error

D) Define the inputs and then define the outputs

Correct Answer: C

Point 1 of the content explicitly lists the two steps for handling errors in an algorithm or program as: 'a. Identify the error. b. Correct the error.'

A mistake in a program that does not violate the language's rules but causes the program to produce an incorrect result is called a:

A) Syntax error

B) Run-time error

C) Compilation error

D) Logic error

Correct Answer: D

The content defines a logic error as 'a mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly.' This is distinct from a syntax error, which violates language rules, and a run-time error, which causes a crash during execution.