List numbering through loop

1 day ago 6
ARTICLE AD BOX

I am trying to create a 3 x 3 kind of matrix where I create 3 lists and append 3 random values to it so that when I print the 3 lists, it looks like a 3 x 3 matrix of random numbers.

import random lst1 =[] lst2 = [] lst3 = [] for i in range(1,4): for j in range(1,4): lst(i).append(random.randint(1,101)) print(lst(i))

This is giving me the below error:

--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[5], line 8 6 for i in range(1,4): 7 for j in range(1,4): ----> 8 lst(i).append(random.randint(1,101)) 9 print(lst(i)) NameError: name 'lst' is not defined

What I'm expecting is that the loop should create 3 lists like :

lst1, lst2 and lst3

I'm new to python, so not able to figure out.

Read Entire Article