Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python 3*3 grid layout with letters

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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('-----')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading