I want to get a 3*3 grid with randomly assign letters.
I tried the following code
import random
def Random_Alpha():
l = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
return l[random.randint(0,25)]
nums = []
for i in range(3):
nums.append([])
for j in range(1, 4):
nums[i].append(print(Random_Alpha()))
print("3X3 grid with letters:")
print(nums)
I got the following output
T
B
T
S
R
K
A
T
S
3X3 grid with letters:
[[None, None, None], [None, None, None], [None, None, None]]
But I need to get following output
T | S | A
---------
B | R | T
---------
T | K | S
>Solution :
import random
def Random_Alpha():
l = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
return l[random.randint(0,25)]
nums = []
for i in range(3):
nums.append([])
for j in range(1, 4):
nums[i].append(Random_Alpha())
print("3X3 grid with letters:")
for i in range(3):
print(*nums[i],sep='|')
print('-----')