Write Python code that uses nested loops to display the following pattern:
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
.
.
.
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
for i in range(8):
lst = []
for j in range(i):
lst.append(2 ** j)
lst.append(2 ** i)
for j in range(i - 1, -1, -1):
lst.append(2 ** j)
print(*lst)
Comments
Leave a comment