In: Computer Science
# *************************************************
# COP3375
# Student's full name ( <<< your name goes here)
# Week 8: Assignment 1
# *************************************************
# Write your code below:
# (a) create a new empty stack
# (b) append items onto the stack
# (c) print the stack contents
# (d) pop an item off the stack
# (e) print the removed item
# (f) print the stack contents again
[1, 2, 3, 4]
4
[1, 2, 3]
Code:
# *************************************************
# COP3375
# Student's full name ( <<< your name goes here)
# Week 8: Assignment 1
# *************************************************
# Write your code below:
# (a) create a new empty stack
# (b) append items onto the stack
# (c) print the stack contents
# (d) pop an item off the stack
# (e) print the removed item
# (f) print the stack contents again
#defining the stack
stack = []
#adding items to the stack
stack.append(1)
stack.append(2)
stack.append(3)
stack.append(4)
#printing the stack content
print(stack)
#popping an element from the stack and storing its value in a variable
poppedItem = stack.pop()
#printing the popped item from the stack
print(poppedItem)
#printing the stack value
print(stack)
Output:
Code screenshot: