In a program processing a list of numbers, the objective is to print all numbers until a negative number is encountered. Which control statement would be apt for this task?
- break
- for
- if
- while
A while loop is apt for this task because it allows you to repeatedly check if the current number is negative and, if not, print it. When a negative number is encountered, the loop terminates, ensuring only non-negative numbers are printed.
Loading...
Related Quiz
- You have identified a performance issue in a critical section of your Python code. Which Python profiling tool would you use to analyze the execution time of this code section and identify the bottleneck?
- In terms of encapsulation, why might a developer use property decorators instead of directly accessing an attribute?
- In Python, which keyword is used to define a metaclass within a class definition?
- In list comprehensions, the ______ keyword can be used to filter out specific values.
- How can you achieve the symmetric difference of two sets in Python?