Question: Continuing on with your Stack class implementation from the previous exercise, extend the Stack class by adding the search ( self, item) method. This method

 Continuing on with your Stack class implementation from the previous exercise,extend the Stack class by adding the search ( self, item) method.

Continuing on with your Stack class implementation from the previous exercise, extend the Stack class by adding the search ( self, item) method. This method searches the stack for the item passed as an argument and returns its position, starting from the top of the stack. I.ement that is on the top of the stack is considered to be at position 1. For example, the following code fragment: my_stack = stack () my_stack.push(100) my_stack.push(101) my_stack.push(102) print (my_stack. search(100)) produces: 3 If the stack contains the item, then the function should return the position. However, if the item is not in the stack, then the function should raise a ValueError exception and print "ERROR: The item is not in the stack.". Submit the entire Stack class definition in the answer box below. Keep a copy of your solution to this task because you will be extending it step bep in subsequent tasks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!