Given the conditional if temperature > 30: message = "Hot" elif temperature > 20: message = "Mild" else: message = "Cool", what value is assigned to message when temperature is 25?
01 Programming Foundations and Problem Solving Online Quiz Questions
Use this free practice quiz with 20 questions to review 01 Programming Foundations and Problem Solving, test your knowledge, and prepare for your next test or exam.
True or false: A loop can become infinite if its condition never becomes false and its repeated work never makes progress toward termination.
- A
True
- B
False
Which computational-thinking practice means breaking a large problem into smaller tasks?
Complete the statement: An algorithm must be , meaning that it eventually terminates for valid input.
Which statement correctly distinguishes parameters from arguments in a function?
- A
Parameters are supplied values, while arguments are names in the definition.
- B
Parameters and arguments are unrelated to function calls.
- C
Parameters are names in the definition, while arguments are supplied values.
- D
Parameters are return values, while arguments determine scope.
Select all statements that are supported by the guidance on loops.
- A
A
forloop is useful when processing each item in a collection. - B
Every
forloop must use a numeric index. - C
A loop should make progress toward a clear termination condition.
- D
Every loop must contain a
breakstatement.
True or false: A method is a function associated with an object or class and is often called through that object.
- A
True
- B
False
What object-oriented concept allows code to use a common interface while different object types provide different implementations?
Complete the statement: In the indexing convention described, the first element of an array is at index .
A designer is modeling a Car that contains an Engine. Which relationship is generally the better choice, and why?
- A
Inheritance, because a car is a type of engine
- B
Composition, because a car has or uses an engine
- C
Polymorphism, because an engine is always a subclass of car
- D
Abstraction, because cars do not have behavior
Select all actions that are recommended debugging strategies.
- A
Read the complete error message and identify the relevant line.
- B
Reproduce the problem with the smallest useful input.
- C
Change many things at once so the fix is faster.
- D
Inspect intermediate values and compare behavior with a hand-worked example.
Design and explain an algorithm that counts how many values in a collection are greater than a specified threshold. Describe the key inputs and steps, explain how you would test it, and state how its running time grows as the collection size increases.
Which statement best explains the distinction described between static and dynamic typing?
- A
Static typing means all values are strings.
- B
Static typing means errors can occur only at runtime.
- C
Static typing generally checks a variable's type before execution.
- D
Static typing prevents a program from using functions.
Which statement best distinguishes a compiler from an interpreter?
- A
An interpreter executes source code during program execution, while a compiler translates source code into lower-level code.
- B
A compiler executes source code line by line, while an interpreter produces a standalone executable.
- C
A compiler stores variables, while an interpreter defines functions.
- D
An interpreter checks only syntax, while a compiler checks only runtime errors.
True or false: A for loop is generally the more appropriate choice when processing every item in a collection.
- A
True
- B
False
What programming term describes a loop that never makes progress toward its termination condition?
A developer breaks a large application requirement into smaller, manageable tasks before designing the solution. Which computational-thinking practice is being applied?
- A
Abstraction
- B
Pattern recognition
- C
Decomposition
- D
Evaluation
An algorithm counts how many values in a collection are greater than a threshold by examining each value exactly once. What is its running-time classification in terms of the number of values, n?
- A
O(1)
- B
O(n)
- C
O(n2)
- D
O(logn)
A designer needs to model a Car that uses an Engine. Which design choice best follows the guidance in the material?
- A
Use inheritance because every useful relationship should be an inheritance relationship.
- B
Use inheritance because an engine is a specialized kind of car.
- C
Use composition because a car contains or uses an engine.
- D
Use neither because objects cannot collaborate across classes.
A function is required to count values greater than 10. It runs successfully, but its condition is written as value >= 10, so it incorrectly includes 10. What type of error is present?