Python Tutorial

Python Home

Python Methods

Python String Methods

Python Interview Programs

Python Common ProgramsPython Array ProgramsPython Converter ProgramsPython Star Patterns ProgramPython Number Patterns ProgramPython Alphabet Patterns Program

Python Reference

ASCII Table

Python Number Pattern 62

Last Updated:

Python Number Pattern 62

Try to print the following number pattern using Python.

Print This Output
1    2    3    4    5    6    7    8    9   10
36  37   38   39   40   41   42   43   44   11
35  64   65   66   67   68   69   70   45   12
34  63   84   85   86   87   88   71   46   13
33  62   83   96   97   98   89   72   47   14
32  61   82   95  100   99   90   73   48   15
31  60   81   94   93   92   91   74   49   16 
30  59   80   79   78   77   76   75   50   17
29  58   57   56   55   54   53   52   51   18
28  27   26   25   24   23   22   21   20   19  

Source Code

Python Compiler
low = 0 high = 9 n = 1 arr = [[None]*10 for _ in range(10)] for i in range(0, 5): for j in range(low, high+1): arr[i][j] = n n += 1 for j in range(low+1, high+1): arr[j][high] = n n += 1 for j in range(high-1, low-1, -1): arr[high][j] = n n += 1 for j in range(high-1, low, -1): arr[j][low] = n n += 1 low += 1 high -= 1 print("Perfect Square Spiral\n") for i in range(0, 10): for j in range(0, 10): print("%3d" % (arr[i][j]), end=" ") print()

Share this Page

Meet the Author