Answer to Question #232087 in Python for kaavya

Question #232087

Striped Rectangle

Given an integer number M, N as input. Write a program to print a striped rectangular pattern of M rows and N columns using (+ and -) character.

Input

The first line of input is an integer M. The second line of input is an integer N.

Explanation

In the given example the striped rectangular pattern of

7 rows and 5 columns. Therefore, the output should be

+ + + + +

- - - -

+ + + + +

- - - - -

+ + + + +

- - - - -

+ + + + +


Sample Input 1

5

7

Sample Output 1

+ + + + + + +

- - - - - - -

+ + + + + + +

- - - - - - -

+ + + + + + +

Sample Input 2

7

5

Sample Output 2

+ + + + +

- - - - -

+ + + + +

- - - - -

+ + + + +

- - - - -

+ + + + +




1
Expert's answer
2021-09-01T23:57:33-0400
M = int(input("Enter rows    (M): "))
N = int(input("Enter columns (N): "))


for i in range(0,M):
      s=""
      if(i%2==1):
            for j in range(0,N):
                  s = s+"-"
      else:
            for j in range(0,N):
                  s = s+"+"
      print(s)

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