Answer to Question #303535 in Python for pranith

Question #303535

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


1
Expert's answer
2022-02-28T01:07:16-0500
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))

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