PrettyPrint

def prettyprint(num): if num == 1: return [1] if num < 1: return [] overalllen = (num*2)-1 copyindex = 0 output = list() start = 1 end = overalllen-1 for i in range(num): answer = [num]*overalllen num -= 1 overalllen -= 2 if len(output) != 0: dummy= output[copyindex][:start]+answer+output[copyindex][end:] copyindex += 1 output.insert(copyindex,dummy) if num != 0: output.insert(copyindex,dummy) start += 1 end -= 1 else: output.append(answer) output.append(answer) return output
This is program to print a square filled array based on input number.

if number = 3, answer would be,

3 3 3 3 3
3 2 2 2 3
3 2 1 2 3
3 2 2 2 3
3 3 3 3 3

if number = 4,


4 4 4 4 4 4 4
4 3 3 3 3 3 4
4 3 2 2 2 3 4
4 3 2 1 2 3 4
4 3 2 2 2 3 4
4 3 3 3 3 3 4
4 4 4 4 4 4 4

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.