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
+ + + + +
- - - - -
+ + + + +
- - - - -
+ + + + +
- - - - -
+ + + + +
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)
Comments