Question 4
We want to print the following pattern.
1111
1001
1011
1111
Which of these two snippets is correct?
Snippet-1
n = 4
for i in range(n):
for j in range(n):
if i == 0 or i == n-1 or j == 0 or j == n-1:
print('1', end='')
elif i == j:
print('1', end='')
else:
print('0', end='')
print()
Snippet-2
n = 4
for i in range(n):
row = ''
for j in range(n):
if i in [0, n-1] or j in [0, n-1]:
row += '1'
elif i == j:
row += '0'
else:
row += '1'
print(row)
Only Snippet-1 prints the pattern correctly
Only Snippet-2 prints the pattern correctly
Both snippets print the pattern correctly
Both snippets print incorrect patterns