Answer to Question #255747 in Python for Emre

Question #255747

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


1
Expert's answer
2021-10-28T06:05:08-0400
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)

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