Which Python collection is most appropriate when a program needs to test membership frequently and remove duplicate values?
8 Fundamental Programming Techniques Online Quiz Questions
Use this free practice quiz with 20 questions to review 8 Fundamental Programming Techniques, test your knowledge, and prepare for your next test or exam.
True or false: A binary search can reliably find a target in an unsorted collection because it compares the target with the middle item at each step.
- A
True
- B
False
What programming term means a finite, precise procedure for solving a problem?
Complete the statement: In loop reasoning, a condition that remains true at a particular point in every iteration is called an .
Which statement correctly compares Python's sorted() function with the list.sort() method?
- A
sorted() returns a new list, while list.sort() changes the list in place.
- B
sorted() changes a list in place, while list.sort() returns a new list.
- C
Both sorted() and list.sort() always leave the original list unchanged.
- D
Both sorted() and list.sort() require the list to contain only numbers.
Which testing approaches should a systematic test plan include? Select all correct choices.
- A
Typical cases with ordinary valid data
- B
Boundary cases such as an empty collection or a minimum value
- C
Invalid cases such as malformed text or an impossible value
- D
Regression cases that previously exposed a defect
- E
Only typical cases, because unusual inputs are outside the program's purpose
True or false: A function that calculates a result should generally return that result rather than print it directly.
- A
True
- B
False
What search method repeatedly halves a sorted search range and has worst-case growth of O(logn) search steps?
Complete the comparison: Python's returns a new sorted list, whereas changes an existing list in place.
Which elements belong in a useful function contract? Select all correct choices.
- A
Inputs and accepted forms
- B
The returned output
- C
Side effects on files, displays, or other external state
- D
Errors or failure behavior
Which approach best follows the material's guidance for handling exceptions in a program that expects invalid user input?
- A
Catch every possible exception at the top level and continue silently.
- B
Catch a specific expected exception at the level where the program can respond meaningfully.
- C
Avoid handling exceptions because they always indicate bugs in the program.
- D
Use a broad except clause around the entire application to simplify debugging.
The integrated word-frequency report is divided into several functions. Explain how this decomposition improves testability and clarity, identify the principal responsibility of each function, and state how the program makes ordering deterministic when words have equal frequencies.
What is the time complexity of the selection_sort implementation described in the material?
- A
O(n)
- B
O(n2)
- C
O(logn)
- D
O(nlogn)
True or false: The line shown in a traceback is necessarily the location where the original incorrect value was created.
- A
True
- B
False
A programmer wants to test a function that processes a collection. Which testing choice best follows the systematic testing guidance?
- A
Use only ordinary valid inputs because they represent normal use.
- B
Include boundary cases such as an empty collection, zero, or one item.
- C
Replace the algorithm with a larger program before testing it.
- D
Test only inputs that are expected to produce a successful result.
A program receives a group of tags and must remove repeated tags while frequently checking whether a tag is present. Which Python collection is the most suitable choice?
- A
A tuple, because it is ordered and immutable.
- B
A list, because it is mutable and preserves order.
- C
A set, because it supports membership tests and removes duplicates.
- D
A dictionary, because every collection should use key–value pairs.
A function calculates the total of a list of prices, and the result may later be used by both a report and an automated test. Which design is most appropriate?
- A
Return the result from the calculation function and let another part handle display.
- B
Print the result inside the calculation function so every caller sees it.
- C
Store the result in global state instead of returning it.
- D
Raise an exception whenever the result needs to be displayed.
Before applying binary search to a collection, which condition must hold for the algorithm's discard-half reasoning to be valid?
- A
The collection must contain only strings.
- B
The target must be the first item in the collection.
- C
The collection must be mutable.
- D
The data must be sorted.
What programming term names a condition that remains true at a particular point in every iteration of an algorithm?
Using the find_index function described in the material, what value is returned by find_index([4, 8, 15], 8)?