in,a hotel they are 'n' rooms for odd rooms the bulb is on for even room bulb is off..
on is represented as 1
off is represented as 0
n = 5
output
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
n = 6
output
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
n = int(input("Enter number: "))
ar_ = [str(i%2) for i in range(1,n+1)]
_ar = ar_[-1:] + ar_[:-1]
res = []
for i in range(n):
if i%2 == 1:
res.append(" ".join(_ar))
else:
res.append(" ".join(ar_))
print("\n".join(res))
Comments
Leave a comment