Q:

How to print a 3x3 2D array using elements from a list in python 3?

I have wrote a code that displays a list.
import random

def Rand(start, end, num): 
    res = [] 

    for j in range(num): 
        res.append(random.randint(start, end)) 

    return res

num = 9
start = 1
end = 100
numbers = [(Rand(start, end, num))]
print(numbers)

The output is 9 random numbers in a list.
[[10, 32, 86, 84, 46, 91, 71, 52, 7]]

I would like to print random numbers in a 3x3 2D array.
10 32 86 
84 46 91 
71 52 7

A:

I'll skip the randomization part as it is not relevant to your question. In general, to split a list into n-sized chunks, you can simply slice the list while iterating the index in n steps:
numbers = [10, 32, 86, 84, 46, 91, 71, 52, 7]
n = 3
print([numbers[i:i+n] for i in range(0, len(numbers), n)])

This outputs:
[[10, 32, 86], [84, 46, 91], [71, 52, 7]]

Or if you want the output to look like a 3x3 2D array:
print('\n'.join(' '.join(map(str, numbers[i:i+n])) for i in range(0, len(numbers), n)))

This outputs:
10 32 86
84 46 91
71 52 7

Note that the numbers variable in your question holds a list of a list of numbers, rather than a list of numbers. You should make the assignment numbers = Rand(start, end, num) instead without unnecessarily enclosing it in another list.

