import random class Matrix: def __init__(self, lines, cols): self.m = self.initialize(lines, cols) def initialize(self, lines, cols): m = {} m["lines"] = lines m["columns"] = cols for i in range(m["lines"]): for j in range(m["columns"]): m[i,j] = random.randrange(10) return m def show(self): for i in range(self.m["lines"]): for j in range(self.m["columns"]): print self.m[i,j], print def set(self, letter): size = self.m["lines"] if letter == 'Z': for i in range(self.m["lines"]): for j in range(self.m["columns"]): if i == 0 or i == size-1 or i + j == size-1: self.m[i,j] = "*" else: self.m[i,j] = " " # It runs like this: # # >>> m = Matrix(12, 12) # >>> m.show() # 5 1 3 9 7 3 0 7 6 1 1 0 # 4 3 8 4 5 5 7 0 7 3 8 8 # 2 5 0 4 3 0 4 4 4 7 4 3 # 7 3 1 8 1 9 9 5 6 6 4 9 # 8 0 1 3 8 1 2 4 1 0 1 8 # 2 2 7 9 3 4 1 1 0 9 3 0 # 4 9 4 7 3 1 7 9 3 4 7 7 # 4 3 0 0 0 5 6 0 0 1 9 4 # 4 5 7 7 0 4 2 3 3 4 4 2 # 5 9 3 5 6 8 2 0 5 7 3 2 # 7 9 4 8 8 2 6 2 4 0 1 8 # 9 8 9 3 8 6 9 6 4 4 0 1 # >>> m.set("Z") # >>> m.show() # * * * * * * * * * * * * # * # * # * # * # * # * # * # * # * # * # * * * * * * * * * * * * # >>>