Counting nested loop output

The function in Listing 1 prints two messages inside nested loops.

Listing 1: Printing messages from nested for loops (Question 1).
def trace_nested_for_loop() -> None:
    # Report which loop is running.
    for i in range(1, 4):
        print("Outer Loop")
        for j in range(1, 3):
            print("Inner Loop")


trace_nested_for_loop()

How many times does trace_nested_for_loop print "Outer Loop" and "Inner Loop"?

  1. It prints "Outer Loop" and "Inner Loop" 3 times.
  2. It prints "Outer Loop" 3 times and "Inner Loop" 6 times.
  3. It prints "Outer Loop" 3 times and "Inner Loop" 2 times.
  4. It prints "Outer Loop" and "Inner Loop" once.
  • range(start, stop, step) supplies integers from start toward, but excluding, stop.
    • step defaults to 1, and range(stop) starts at 0.
    • list(range(2, 7, 2)) is [2, 4, 6]; list(range(5, 1, -2)) is [5, 3].
    • A range is empty when the step cannot reach the stop; a zero step raises ValueError.
  • list collects the supplied values in a new list.