Answer to Question #218385 in Python for kaavya

Question #218385

Write a program to print a rectangle pattern of M rows and N columns using the characters as shown below.

In the given example,

3 rows and 10 columns.Therefore, the output should be

+----------+

|      |

|      |

|      |

+----------+


1
Expert's answer
2021-07-18T01:24:12-0400
def main():
    n, m = map(int, input('Enter rectangle size').split())
    if n < 2 or m < 2:
        print('Please enter bigger dimention!')
        return
    for i in range(1, n+1):
        for j in range(1, m+1):
            if (i == 1 and j == 1) or (i == 1 and j == m) or (i == n and j == 1) or (i == n and j == m):
                print('+', end='')
            elif i == 1 or i == n:
                print('-', end='')
            elif j == 1 or j == m:
                print('|', end='')
            else:
                print(' ', end='')
        print()
        
main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS