Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can i get help with this python code pls Problem 1A (Stack Implementation) In th

ID: 3828104 • Letter: C

Question

Can i get help with this python code pls

Problem 1A (Stack Implementation) In the previous assignment, you implemented a queue. A stack is a similar type of data structure, but instead of using the first-in-first-out principle of a queue, a stack uses last-in-first out. This means that the next item taken from a stack is the most recent item that was inserted. Operations on a stack occur in the same way as they did for the plate stacking problems that were used in Assignment 1.1. Create a list type variable that will be used to store the stack data in a file called stack.py. Implement the following functions inside that file: 1) push(value): Adds the argument value onto the top of the stack (i.e., the end of the list variable). 2) pop0: If the stack is empty, this function returns None. Otherwise, this function removes and returns the top value from the stack (i.e., the last value in the list variable). 3) is empty 0: Returns True if the stack is empty (i.e., has no items), False otherwise. 4) getlist0: Returns the list that stores the stack data. 5) clear0: Removes all data from the stack. You can use the stacktester.py file from cuLearn to verify the operations of your stack are working as they should be.

Explanation / Answer

Hi

I have alter the code. Use append instead of push. The correct code is:

getlist=[]
#def stack(getlist)
print("The stack should initially be: []")
print(getlist)
print("Trying to pop from an empty stack, should be None")
print(getlist)
print("Pushing 0 to stack, should be [0]")
getlist.append(0)
print(getlist)
print("Pushing 1 to stack, should be [0, 1]")
getlist.append(1)
print(getlist)
print("Pushing 2 to stack, should be [0, 1, 2]")
getlist.append(2)
print(getlist)
print("Pushing 3 to stack, should be [0, 1, 2, 3]")
getlist.append(3)
print(getlist)
print("Pop should return 3")
print(getlist.pop())
print("The stack is :")
print(getlist)
print("Pop should return 2")
print(getlist.pop())
print("The stack is :")
print(getlist)
print("The stack should be: [0, 1]")
print("Your stack is ")
print(getlist)
print("Pushing 4 to stack, should be [0, 1, 4]")
getlist.append(4)
print("Your stack is ")
print(getlist)
print("Pushing 5 to stack, should be [0, 1, 4, 5]")
getlist.append(5)
print("Your stack is ")
print(getlist)
print("Pop should return 5")
print(getlist.pop())
print(getlist)
print("The stack should be: [0, 1, 4]")
print("Your stack is ")
print(getlist)
print("Pop should return 4")
print(getlist.pop())
print("The stack should be: [0, 1]")
print("Your stack is ")
print(getlist)
print("Clearing stack")
getlist.clear()
print(getlist)
print("The stack should be: []")
print("Your stack is ", getlist())
print(getlist)
print("Pop should return None")
print(getlist.pop())
print("The stack should be: []")
print(getlist)

please write comment if you still have a doubt.