Python Programming - Loops

Exercise : Loops - General Questions
  • Loops - General Questions
16.
How can you create an infinite loop?
for i in range(10):
while True:
for i in range(1, 0, -1):
while False:
Answer: Option
Explanation:
while True: creates an infinite loop, as the condition is always true.

17.
What is the purpose of the enumerate function when used with a for loop?
Counts the total number of iterations.
Iterates over the values of a sequence.
Returns the index and value of each element in a sequence.
Reverses the order of iteration.
Answer: Option
Explanation:
The enumerate function is used in a for loop to iterate over both the index and value of each element in a sequence.

18.
What is the purpose of the reverse parameter in the range function?
It reverses the order of elements in a list.
It creates a reversed range from a specified end to start.
It reverses the order of iteration in a loop.
It has no effect on the range function.
Answer: Option
Explanation:
The range function's reverse parameter is used to create a reversed range from a specified end to start.

19.
In Python, what does the pass statement do when used in a loop?
Exits the loop prematurely.
Does nothing and is used as a placeholder.
Repeats the loop indefinitely.
Terminates the program.
Answer: Option
Explanation:
The pass statement does nothing and is used as a placeholder.

20.
Which function is used to find the minimum value from a sequence?
min()
minimum()
min_value()
find_min()
Answer: Option
Explanation:
The min() function is used to find the minimum value from a sequence in Python.