import random as r a = [] size = 20 for i in range(size): b = [] for o in range(size): n = r.randint(1,10) if n > 8: b.append('a') else: b.append('0') a.append(b) with open("table.txt","w") as file: for line in a: for item in line: file.write(f"{item} ") file.write("\n")