Question: Hello, please help me with my Python homework! Just getting a couple of errors. Cheers. Here's my code: def pop ( self ): -------------------------------------------------------

Hello, please help me with my Python homework! Just getting a couple of errors. Cheers.

Hello, please help me with my Python homework! Just getting a couple

of errors. Cheers. Here's my code: def pop(self): """ ------------------------------------------------------- Pops and

Here's my code:

def pop(self):

"""

-------------------------------------------------------

Pops and returns the top of stack. The data element is

removed from the stack. Attempting to pop from an empty

stack throws an exception.

Use: value = stack.pop()

-------------------------------------------------------

Returns:

value - the value at the top of stack (?)

-------------------------------------------------------

"""

assert not self.isEmpty(), "Cannot pop from an empty stack"

value = deepcopy( self._values[ self._top ] )

self._top -=1

return value

def peek(self):

"""

-------------------------------------------------------

Returns a copy of the value at the top of the stack without

removing it.

Attempting to peek at an empty stack throws an exception.

Use: value = stack.peek()

-------------------------------------------------------

Returns:

value - a copy of the value at the top of stack (?)

-------------------------------------------------------

"""

#your code goes here

assert len(self.values) > 0, "Cannot peak at an empty stack"

value = deepcopy(self.values[-1])

return value

Test for assertion fails: 'peek' ERROR: 'Stack' object has no attribute 'values' Test 'peek' with various values: '[99]' ERROR: 'Stack' object has no attribute 'values' Test 'peek' with various values: '[11, 22, 33, 44, 55, 66]' ERROR: 'Stack' object has no attribute 'values' Test 'pop' with various values: '[99]' ERROR: Remaining stack incorrect Test 'pop' with various values: '[1,1,1, 1, 1, 1]' ERROR: Remaining stack incorrect

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!