w3resource

Python: Create a 3X3 grid with numbers


Create 3x3 Grid with Numbers

Write a Python program to create a 3X3 grid with numbers.

Visual Presentation:

Python List: Create a 3X3 grid with numbers.

Sample Solution:

Python Code:

nums = []
for i in range(3):
    nums.append([])
    for j in range(1, 4):
        nums[i].append(j)
print("3X3 grid with numbers:")
print(nums) 

Sample Output:

3X3 grid with numbers:
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]

Flowchart:

Flowchart: Create a 3X3 grid with numbers.

For more Practice: Solve these Related Problems:

  • Write a Python program to create a 4x4 grid with numbers.
  • Write a Python program to create a grid with a diagonal pattern.
  • Write a Python program to fill a grid with sequential numbers.
  • Write a Python program to generate a spiral matrix in a grid.

Go to:


Previous: Write a Python program to create a multidimensional list (lists of lists) with zeros.
Next: Write a Python program to read a matrix from console and print the sum for each column. Accept matrix rows, columns and elements for each column separated with a space(for every row) as input from the user.

Python Code Editor:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.