Back
I just want to print the following binary pattern, for the given number of rows.
Binary pattern for N=4
1111000110
1111
000
11
0
Binary pattern for N=5
111110000111001
11111
0000
111
00
1
Try the following code:
n = int(input())ones = Truewhile n > 0: out = ["1"]*n if ones else ["0"]*n ones = not ones n -= 1 print("".join(out))
n = int(input())
ones = True
while n > 0:
out = ["1"]*n if ones else ["0"]*n
ones = not ones
n -= 1
print("".join(out))
Want to learn python to become expert in the concepts of python? Join python training course and get certified
31k questions
32.8k answers
501 comments
693 users