I'm trying to write a code that will return random letters in a 4 * 4 grid. Here is my attempt so far
So I have created a grid like this
[][][][]
[][][][]
[][][][]
[][][][]
using this code:
board = ['[]' * 4 ] * 4
for x in board:
print(x)
and now I'm trying to replace each []
with a letter in it, like [A]
and I tried to do it by implementing this piece of code
import random
import string
for x in row:
print(random.choice(string.ascii_letters))
but the code prints this out..
s
K
U
J
l
e
X
s
instead of a grid, which I expected to be like this...
[A][D][F][T]
[S][D][A][E]
[R][V][B][S]
[O][P][L][K]
what should I change in my code to ensure the output is like the grid mentioned right above?
Here is my full code btw..
import random
import string
board = ['[]' * 4 ] * 4
for row in board:
print(row)
for x in row:
print(random.choice(string.ascii_letters))
Like this:
Output: