my code stock.com

Vipin Raj Manayil Rajan

Python program to draw pattern of order m * n with cell numbers in it
by Vipin Raj Manayil Rajan

Program to draw a patterm of order m * n and fill cell numbers in it.
For example: 3 * 4
+———-+———-+———-+———-+
|    |    |    |    |
| 1   | 2   | 3   | 4   |
|    |    |    |    |
+———-+———-+———-+———-+
|    |    |    |    |
| 5   | 6   | 7   | 8   |
|    |    |    |    |
+———-+———-+———-+———-+
|    |    |    |    |
| 9   | 10   | 11   | 12   |
|    |    |    |    |
+———-+———-+———-+———-+

Snippet options

Download: Download snippet as python-program-to-draw-pattern-of-order-m-n-with-cell-numbers-in-it.py.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

if __name__ == '__main__':
    m = 3
    n = 4

    r1 = "+-------" * n
    r1 = r1 + "+"
    r2 = "|       " * n
    r2 = r2 + "|"

    row = 0
    cell = 1
    while(row<m):
        i=1
        print(r1)
        while(i<4):
            if(i==2):
                k=0
                r3 = ""
                while(k<n):
                    cell = row * n + k
                    cell+=1
                    r3 = r3 + "| " + str(cell).ljust(6)
                    k+=1
                r3 = r3 + "|"
                print(r3)
                i+=1
                continue
            print(r2)
            i+=1
        row+=1
    print(r1)


Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.