350-401 practice question 26 of 35

A script contains the statement •white loop != 999 ’ Which value terminates the loop?

Full set: 358 questions

Domain Automation

Answer options
A: A value equal to 999. Correct answer
B: A value not equal to 999.
C: A value greater than or equal to 999.
D: A value less than or equal to 999.
Correct Answer:
A. A value equal to 999.
Explanation

A while loop continues to execute as long as its conditional expression evaluates to true. In this case, the condition is loop != 999, which translates to "the value of the variable loop is not equal to 999". The loop will only terminate when this condition becomes false. The condition loop != 999 evaluates to false only when the value of loop is exactly 999. Therefore, a value of 999 assigned to the loop variable will terminate the loop.

Why Incorrect

B. A value not equal to 999: Any value not equal to 999 will cause the condition loop != 999 to evaluate to true, making the loop continue, not terminate.
C. A value greater than or equal to 999: While the value 999 would terminate the loop, any value greater than 999 (e.g., 1000) would satisfy the condition 1000 != 999, causing the loop to continue.
D. A value less than or equal to 999: While the value 999 would terminate the loop, any value less than 999 (e.g., 0) would satisfy the condition 0 != 999, causing the loop to continue. ---

References

1. Python Software Foundation. (2024). The Python Tutorial

Section 4.2. while Statements. Python 3.12.3 Documentation. Retrieved from https://docs.python.org/3/tutorial/controlflow.html#while-statements.

Specific Citation: The documentation states

"The while statement is used for repeated execution as long as an expression is true." This confirms the loop's behavior is tied to the truthiness of the condition.

2. Python Software Foundation. (2024). The Python Language Reference

Section 6.10. Comparisons. Python 3.12.3 Documentation. Retrieved from https://docs.python.org/3/reference/expressions.html#comparisons.

Specific Citation: This section defines the != operator as "not equal to". The loop while loop != 999 thus continues as long as loop is not equal to 999

and stops when it is equal.

3. Guttag

J. V. (2016). Lecture 2: Branching

Conditionals

and Iteration. MIT OpenCourseWare

6.0001 Introduction to Computer Science and Programming in Python

Fall 2016.

Specific Citation: The lecture notes on iteration explain that a while loop's body is executed repeatedly as long as the evaluates to True. When the condition becomes False

the program proceeds to the first statement after the loop body.

4. Cisco DevNet. (n.d.). Python Fundamentals for Network Engineers

Module 2: Python Language Basics

Section: "While Loops".

Specific Citation: This learning module explains

"A while loop statement in Python programming language repeatedly executes a target statement as long as a given condition is true." This directly supports the logic that the loop terminates when the condition is false.

Scroll to Top