Inverting of Boolean variable not happening after end of every for loop
I am trying to create a pattern as follows -
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
My output is -
1
0 1
0 1 0
1 0 1 0
1 0 1 0 1
My code is as follows -
N=5
bool_ = True
for row in range(1,N+1):
for i in range(1, row+1):
if i>1:
print(' ', end='')
print(int(bool_), end= '')
bool_ = not bool_
print()
Not sure what is wrong in this. It seems like something to do with range of second for loop.