True or false: Testing and debugging are the same process.
04 — Program Construction and Problem Solving Online Quiz Questions
Use this free practice quiz with 20 questions to review 04 — Program Construction and Problem Solving, test your knowledge, and prepare for your next test or exam.
Which approach best illustrates decomposition when designing a program to calculate an average?
- A
Writing all code in one long function
- B
Dividing a large problem into smaller tasks
- C
Running the program repeatedly without changing it
- D
Replacing valid inputs with default values
Complete the statement: During the average-calculation loop, the invariant is that total always equals .
What programming term describes a separately organized part of a program that can help code be reused and maintained?
Which test input is specifically a boundary-case test for a function that accepts scores from 0 through 100?
- A
A list containing ordinary middle-range scores
- B
A list containing no scores when empty input is not allowed
- C
A list containing the lowest and highest allowed scores
- D
A list containing randomly chosen text values
True or false: Expected invalid user input should generally be handled with exceptions rather than assertions.
- A
True
- B
False
Select all the benefits of modularity described in the material.
- A
It limits the amount of code that must be understood at one time.
- B
It allows individual components to be tested independently.
- C
It requires the same calculation to be copied wherever it is used.
- D
It localizes changes to the relevant component.
What is the exact arithmetic mean of the scores [20, 40, 60, 80]?
Complete the definition: A regression is .
A function calculates an average by dividing the sum by len(scores) - 1 instead of len(scores). What kind of error is this?
- A
Syntax error
- B
Runtime error
- C
Input-validation error
- D
Logic error
Select all actions that belong to the systematic debugging process described in the material.
- A
Reproduce the problem with reliable failing inputs.
- B
Reduce the problem to the smallest case that still fails.
- C
Change many unrelated parts at the same time.
- D
Run the full test suite after confirming the failing test is fixed.
Explain what refactoring is and describe how testing supports a safe refactoring process. Include one example of a refactoring change.
Which comment best follows the guidance that comments should explain why rather than merely repeat what the code does?
- A
Add x to y
- B
divide items by group size
- C
Use integer division because the number of complete groups is required.
- D
Set the variable
A developer is designing a program that calculates examination-score averages. Which approach best applies decomposition?
- A
Writing all program instructions in one long function
- B
Dividing the problem into smaller tasks
- C
Testing only the final program output
- D
Replacing the algorithm with documentation
A programmer wants a function that calculates an average to be easy to test and reuse. Which design best demonstrates high cohesion?
- A
Combine calculation, printing, file access, and input validation in one function
- B
Make every function depend directly on the internal variables of every other function
- C
Separate average calculation from report printing
- D
Copy the average calculation into each report-producing function
True or false: A sufficiently large collection of tests can prove that a program contains no possible errors.
- A
True
- B
False
A program fails intermittently, and a developer has found an input that can reproduce the failure. What should the developer do next to make the cause easier to isolate?
- A
Change many unrelated parts of the program at once
- B
Reduce the problem to the smallest failing input or action sequence
- C
Skip the failing test and run only unrelated tests
- D
Document the correction before investigating the cause
A developer extracts a long block into a function and removes duplicated code while preserving the program's externally observable behavior. What is this practice called?
A function receives user input that is expected to be invalid sometimes, such as text that cannot be converted to a number. Which error-handling approach is most appropriate?
- A
Use an assertion as the normal mechanism for rejecting every invalid user input
- B
Raise or handle a specific exception for the expected invalid input
- C
Catch every possible exception with one broad handler and ignore it
- D
Allow the invalid value to continue without reporting a problem
Using the arithmetic mean, what average does the score list [70, 80, 90] produce?