Bird
0
0

You want to print a 4x4 grid where each cell contains the product of its row and column numbers (starting from 1). Which nested while loop code correctly does this?

hard📝 Application Q8 of 15
Python - While Loop
You want to print a 4x4 grid where each cell contains the product of its row and column numbers (starting from 1). Which nested while loop code correctly does this?
Ai = 0 while i <= 4: j = 0 while j <= 4: print(i * j, end=' ') j += 1 print() i += 1
Bi = 1 while i <= 4: j = 1 while j <= 4: print(i + j, end=' ') i += 1 print() j += 1
Ci = 1 while i < 4: j = 1 while j < 4: print(i * j) j += 1 i += 1
Di = 1 while i <= 4: j = 1 while j <= 4: print(i * j, end=' ') j += 1 print() i += 1
Step-by-Step Solution
Solution:
  1. Step 1: Loop ranges

    Rows and columns start at 1 and go up to 4 inclusive.
  2. Step 2: Inner loop variable reset

    Reset 'j' to 1 at the start of each outer loop iteration.
  3. Step 3: Correct increments and print

    Increment 'j' inside inner loop, 'i' inside outer loop, print product with space, and print newline after inner loop.
  4. Final Answer:

    i = 1 while i <= 4: j = 1 while j <= 4: print(i * j, end=' ') j += 1 print() i += 1 correctly implements this logic.
  5. Quick Check:

    Reset inner variable and print product with correct loops [OK]
Quick Trick: Reset inner loop variable each outer iteration [OK]
Common Mistakes:
MISTAKES
  • Incrementing outer loop variable inside inner loop
  • Using addition instead of multiplication
  • Starting loops from 0 instead of 1
  • Not printing newline after each row

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes