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
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()
Comments
Leave a comment