A while loop takes numbers from the end of a list until it meets a zero.
stack = [3, 0, 2, 1]
total = 0
while stack:
n = stack.pop()
if not n:
break
total += n
print(total, stack)
What does the program print?
Log in to join the discussion.
Loading…