Question

In: Computer Science

Description of the Assignment: Write a Python program to (a) create a new empty stack. Then,...

  • Description of the Assignment: Write a Python program to (a) create a new empty stack. Then, (b) add items onto the stack. (c) Print the stack contents. (d) Remove an item off the stack, and (e) print the removed item. At the end, (f) print the new stack contents:
  • Please use the following comments in your python script:

# *************************************************
# 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

  • Sample Output - Your output should look like something similar to the following:

[1, 2, 3, 4]
4
[1, 2, 3]

Solutions

Expert Solution

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:


Related Solutions

Write a Python program to (a) create a new empty stack. Then, (b) add items onto...
Write a Python program to (a) create a new empty stack. Then, (b) add items onto the stack. (c) Print the stack contents. (d) Remove an item off the stack, and (e) print the removed item. At the end, (f) print the new stack contents:
Description of the Assignment: Write a Python program to create a deque and append few elements...
Description of the Assignment: Write a Python program to create a deque and append few elements to the left and right, then remove some elements from the left, right sides and reverse the deque. Please use the following comments in your python script: # ************************************************* # COP3375 # Student's full name ( <<< your name goes here) # Week 9: Assignment 1 # ************************************************* # Write your code below: # Create a deque # Print a deque # Append to...
Exercise 3: Stack Write a program in Java to manipulate a Stack List: 1. Create Stack...
Exercise 3: Stack Write a program in Java to manipulate a Stack List: 1. Create Stack List 2. Display the list 3. Create the function isEmply 4. Count the number of nodes 5. Insert a new node in the Stack List. 6. Delete the node in the Stack List. 7. Call all methods above in main method with the following data: Test Data : Input the number of nodes : 4 Input data for node 1 : 5 Input data...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
Python Program: Description Create an object-oriented program that uses inheritance to perform calculations on a rectangle...
Python Program: Description Create an object-oriented program that uses inheritance to perform calculations on a rectangle or a square. Specifications Use a Rectangle class that provides attributes to store the height and width of a rectangle. This class should also provide methods that calculate the perimeter and area of the rectangle. Use a Square class that inherits the Rectangle class. This class should set the height and the width of the Rectangle superclass to the length that’s set in the...
Create two lists; one contains 5 elements and the other one is empty. Write a python...
Create two lists; one contains 5 elements and the other one is empty. Write a python program that iterates through the first one, pops the elements from the end of it, then it pushes them one by one to the empty list. As your program iterates through the first list, clean it before processing the data, meaning if any element is like a special character ( , . ; : ) it must be discarded and not gets pushed to...
Python DESCRIPTION Write a program that will read an array of integers from a file and...
Python DESCRIPTION Write a program that will read an array of integers from a file and do the following: ● Task 1: Revert the array in N/2 complexity time (i.e., number of steps) . ● Task 2: Find the maximum and minimum element of the array. INPUT OUTPUT Read the array of integers from a file named “ inputHW1.txt ”. To do this, you can use code snippet from the “ file.py ” file. This file is provided in Canvas....
Python DESCRIPTION Write a program that will read an array of integers from a file and...
Python DESCRIPTION Write a program that will read an array of integers from a file and do the following: ● Task 1: Revert the array in N/2 complexity time (i.e., number of steps) . ● Task 2: Find the maximum and minimum element of the array. INPUT OUTPUT Read the array of integers from a file named “ inputHW1.txt ”. To do this, you can use code snippet from the “ file.py ” file. This file is provided in Canvas....
Python DESCRIPTION Write a program that will read an array of integers from a file and...
Python DESCRIPTION Write a program that will read an array of integers from a file and do the following: ● Task 1: Revert the array in N/2 complexity time (i.e., number of steps) . ● Task 2: Find the maximum and minimum element of the array. INPUT OUTPUT Read the array of integers from a file named “ inputHW1.txt ”. To do this, you can use code snippet from the “ file.py ” file. This file is provided in Canvas....
PYTHON PROGRAM Requirements: 1. Create an empty directory a variable named song_search 2. Repeatedly prompt the...
PYTHON PROGRAM Requirements: 1. Create an empty directory a variable named song_search 2. Repeatedly prompt the user to enter either the title of a song or enter nothing if they have no more songs to enter 3. For each song title entered by the user, split the song title into words by using the split function and splitting on a space. For each word from each song title, ensure the song_search dictionary has a entry with that word as the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT