Print an n × n multiplication grid: row i holds i × 1, i × 2, …, i × n, separated by single spaces.
What to build
A grid made by two loops.
Requirements
- Read
n. - Print
nrows, each holdingnproducts separated by single spaces.
Input
One whole number n from 1 to 12.
Output
n lines of numbers.
Constraints
n is from 1 to 12.
Example
Input:
3
Output:
1 2 3
2 4 6
3 6 9
Why it works
The outer loop picks the row and the inner loop picks the column, so every pair is reached exactly once.
Examples
Example 1 · Input
3
Expected output
1 2 3 2 4 6 3 6 9
Example 2 · Input
1
Expected output
1
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
An inner loop builds one row; the outer loop runs once per row.
Hint 2
" ".join(...) avoids a trailing space.
Solution
Show one correct solution (try it yourself first)
n = int(input())
for i in range(1, n + 1):
print(" ".join(str(i * j) for j in range(1, n + 1)))