NOTE Modify append() function so that it will enable you to push more items using (Y/N): E.g Enter your Choice: 1 Push item to stack: 12 Enter more(y/n): y Push item to stack: 15 Enter more(y/n): n...



NOTE


Modify append() function so that it will enable you to push more items using (Y/N): E.g


Enter your Choice: 1 Push item to stack: 12 Enter more(y/n): y Push item to stack: 15 Enter more(y/n): n


Modify pop() function so that it will confirm user want to delete item or not,(give warning that item deleted cannot be recovered) using (Delete/Cancel): E.g (D/C)


Add There (#) comment and declear all the line of this coding properly.


ALGORITHM Steps:




For Array/List Based, Declare and initialize necessary variables, eg size.



Initializean empty list asmyStack;


1.Usewhile loop to get input from user.


2.Continue while loop until list size and defined size are same;


if len(list) == size


print “Stack overflow“


else


Read item from user


myStack = item


3.For next append operation, goto step 2.


4.For pop operation, checks that your defined size is equal to list size or not;


if len(list) == size print "Stack underflow"


else


myStack = pop(); Display item


5.For next pop operation, goto step 4.


6.Stop



Modify the algorithm given,stack.py, to create a Menu that enable user to enter option for stack operations



  • append()

  • pop()

  • Count last item of the list



  • len(list) == 0 and check whether list is full or not

  • len()

  • print()



Example of INPUT / OUTPUT<br>Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit<br>1<br>Enter the number to be pushed: 11<br>Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit<br>1<br>Enter the number to be pushed: 22<br>Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit<br>1<br>Enter the number to be pushed: 33<br>Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit<br>2<br>The number Popped is: 33<br>Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit<br>3<br>The stack is 11 22<br>Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit<br>4<br>The size of the stack is 2<br>

Extracted text: Example of INPUT / OUTPUT Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit 1 Enter the number to be pushed: 11 Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit 1 Enter the number to be pushed: 22 Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit 1 Enter the number to be pushed: 33 Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit 2 The number Popped is: 33 Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit 3 The stack is 11 22 Enter the operation to be performed: 1) append 2) pop 3) print 4) len 5) exit 4 The size of the stack is 2

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here