QUESTION IMAGE
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
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\).
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
12