24
QuizMultiple Choice

Readable Code — Unit test

Question 24 • VA-Information Technology Fundamentals B

Why is the len ( ) function useful when using a loop to iterate through a stack?

Answer
A
The len ( ) function will print the elements of the stack.
B
The len ( ) function will run with each iteration, printing the element number each time.
C
The len ( ) function will tell the program the number of elements in the stack.
D
The len ( ) function will remove the duplicate elements in the stack.

Explanation

The len() function returns the number of elements in a stack. A loop can use that count to determine how many elements it needs to process. It does not print or remove elements by itself.

AI-written and checked against the verified answer.