Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

question 2 given the following code, how many times does the inner loop…

Question

question 2
given the following code, how many times does the inner loop execute?
for i in range(3):
for j in range(4):
print(i, , j)
20
12
4

Explanation:

Step1: Analyze outer loop

The outer loop for i in range(3) runs 3 times (i = 0, 1, 2).

Step2: Analyze inner loop

For each iteration of the outer loop, the inner loop for j in range(4) runs 4 times (j = 0, 1, 2, 3).

Step3: Calculate total inner - loop executions

Using the multiplication principle, the total number of inner - loop executions is \(3\times4=12\).

Answer:

12