Answer to Question #250143 in Python for foodie

Question #250143
We can push a total of 100 values

Value Pushed in Stack 1 is 1

Value Pushed in Stack 1 is 2

Value Pushed in Stack 1 is 3

Value Pushed in Stack 1 is 4

.....

Value Pushed in Stack 1 is 60

Value Pushed in Stack 2 is 1

..........

Value Pushed in Stack 2 is 40



Print Pushed Values:

60 59 58 57..... 6 5 4 3 2 1

40 39 38.... 3 2 1



Pushing Value in Stack 1 is 101

Stack Full! Cannot Push



60 is being popped from Stack 1

59 is being popped from Stack 1

58 is being popped from Stack 1

...........

...........

3 is being popped from Stack 1

2 is being popped from Stack 1

1 is being popped from Stack 1

Stack Empty! Cannot Pop
I need a program for these
1
Expert's answer
2021-10-12T00:37:53-0400
stack1 = []
stack2 = []


for number in range(1,61):
    stack1.append(number)
    print(f"Value Pushed in Stack 1 is {number}")
for number in range(1,41):
    stack2.append(number)
    print(f"Value Pushed in Stack 2 is {number}")
print("Print Pushed Values:")
counter=len(stack1)-1
while(counter>=0):
    print(f"{stack1[counter]}",end=" ")
    counter-=1


for number in range(61,103):
    if len(stack1)<=100:
        stack1.append(number)
        print(f"Pushing Value in Stack 1 is {number}")
    else:
        print("Stack Full! Cannot Push")


while(len(stack1)>0):
    print(f"{stack1.pop()} is being popped from Stack 1")
        
if len(stack1)==0:
    print("Stack Empty! Cannot Pop")

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