Answer to Question #302377 in Python for vineeth

Question #302377

bulb states pattern

bulb states pattern program contain input is a single line containing a positive integer n representing the number of rooms in the building and the output should contain n lines , each line containing the state of the bulb in the room numbered from 1 to n in the form of 0 and 1.

example:

input 1 :- 5

output 1 :-

0 1 0 1 0

0 1 0 1 0

0 1 0 1 0

0 1 0 1 0

0 1 0 1 0



1
Expert's answer
2022-02-24T17:12:58-0500
print("Enter N:", end='')
n = int(input())
array = [[0] * n for i in range(n)]
for i in range(n):   
    for j in range(n):
        if j % 2 == 0:
            array[i][j] = 0
        else:
            array[i][j] = 1
print()
for i in range(n):
    for j in range(n):
        print(array[i][j], end=' ')
    print()

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