2 of 6
Print this grid using nested loops:
1 2 3 4
1 2 3 4
1 2 3 4
# Print a 3-row, 4-column number grid # Each row should show: 1 2 3 4 for row in range(___): for col in range(___): print(___, end=" ") print()
You need 3 rows, so the outer loop should run 3 times: range(3)
Each row prints 1, 2, 3, 4. Use range(1, 5) for the inner loop to get those numbers.
Use print(col, end=" ") to print on the same line, then print() after the inner loop to move to the next line.
for row in range(3): for col in range(1, 5): print(col, end=" ") print()
How it works:
end=" " keeps everything on one lineprint() moves to the next line after each rowβ Standard library: heapq, collections, itertools, math, random, functools, datetime, bisect
β Functions, classes, recursion, print()
β No file system, subprocess, OS access, or network requests
β No pip install (all supported modules are pre-loaded)
β±οΈ 5 second execution time limit