Free Practice Quiz Question List

05 Loops and Repetition Online Quiz Questions

Use this free practice quiz with 20 questions to review 05 Loops and Repetition, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

What values are produced by Python's range(2, 11, 2)?

  1. A

    2, 4, 6, 8, 10, 12

  2. B

    2, 4, 6, 8, 10

  3. C

    1, 3, 5, 7, 9

02
True or false
1 point

True or false: A for loop is usually a clear choice when a program should perform an action once for every item in a collection.

  1. A

    True

  2. B

    False

03
Fill in the blank
1 point

Complete the sentence: In the loop that counts values in [4, 7, 10, 13, 16], even_count is increased only when a number is .

04
Written response
1 point

What is the programming term for a variable that records how many times an event occurs?

05
Choose one
1 point

What does a break statement do when it executes inside a nested loop?

  1. A

    It terminates every loop in the program.

  2. B

    It skips the current iteration and continues the same loop.

  3. C

    It immediately terminates the innermost loop.

  4. D

    It restarts the outer loop from its first iteration.

06
True or false
1 point

True or false: In Python, a loop's else clause runs when the loop finishes normally, but not when the loop ends through break.

  1. A

    True

  2. B

    False

07
Choose all
1 point

Select all situations for which a Python for loop is generally the clearest choice.

  1. A

    Processing every item in a list

  2. B

    Repeating a known number of times

  3. C

    Continuing until user input changes a condition

  4. D

    Iterating through a range of values

08
Fill in the blank
1 point

Complete the debugging advice: To make while count <= 5 terminate in the example, the loop must update the .

09
Written response
1 point

A nested loop has an outer loop that runs 3 times and an inner loop that runs 4 times for each outer iteration. How many times does the inner loop body execute in total?

10
Choose one
1 point

Which initialization correctly prepares an accumulator named product to multiply the factors 2, 3, and 4?

  1. A

    product = 0

  2. B

    product = 1

  3. C

    product = -1

  4. D

    product = None

11
Choose all
1 point

Select all practices that help prevent an input-driven while loop from becoming infinite.

  1. A

    The loop condition can eventually become false

  2. B

    The state controlling the condition is updated toward termination

  3. C

    The loop must always execute exactly five times

  4. D

    Unexpected input is handled so it cannot prevent progress

12
True or false
1 point

True or false: The continue statement skips the remainder of the current iteration and begins the next iteration.

  1. A

    True

  2. B

    False

13
Open ended
1 point

Describe an algorithm that uses a loop to find the largest value in [12, 5, 19, 8, 14]. State the initialization, the comparison and update performed for each remaining value, and the final result.

14
Choose one
1 point

A loop classifies the values [3, -2, 0, 8, -1] into positive, negative, and zero categories. Which final counter values are correct?

  1. A

    positive = 2, negative = 3, zero = 1

  2. B

    positive = 3, negative = 2, zero = 1

  3. C

    positive = 3, negative = 1, zero = 2

  4. D

    positive = 2, negative = 2, zero = 1

15
Choose one
1 point

A program must print each name in a list exactly once, and the list itself determines how many names there are. Which approach best matches the material?

  1. A

    Use a for loop to process each item in the collection.

  2. B

    Use a while loop with a condition that is always true.

  3. C

    Use break before examining any items.

  4. D

    Use range() without referring to the collection.

16
Choose one
1 point

Which sequence is produced by range(2, 11, 2) in a Python for loop?

  1. A

    2, 4, 6, 8, 10, 12

  2. B

    1, 3, 5, 7, 9, 11

  3. C

    2, 4, 6, 8, 10

  4. D

    2, 3, 4, 5, 6, 7, 8, 9, 10

17
Choose one
1 point

Consider numbers = [4, 7, 10, 13, 16] and a counter that starts at zero and increases only when number % 2 == 0. What is the counter's final value?

  1. A

    5

  2. B

    3

  3. C

    2

  4. D

    0

18
Choose one
1 point

In a nested loop, the statement break executes inside the inner loop. What does it do?

  1. A

    Both loops stop immediately.

  2. B

    Only the outer loop stops.

  3. C

    The break is ignored inside nested loops.

  4. D

    Only the inner loop stops.

19
Written response
1 point

What programming term names the step that establishes a loop's starting value or data source?

20
Written response
1 point

A nested loop has for row in range(3): as its outer loop and for column in range(4): as its inner loop, with one statement in the inner body. How many times does that body statement execute?