Question: use stack.py as your starting point for both the stack2.py and stack3.py. please use python language from pythonds.basic import Stack s=Stack print(s.isEmpty) s.push(4) 5.push('dog) print(s.


from pythonds.basic import Stack s=Stack print(s.isEmpty) s.push(4) 5.push('dog) print(s. peek) s.push(True) print(s.size() print(s.isEmpty()) s.push(8.4) print(s.pop()) print(s.pop). print(s.size() class Stack: def init__(self): self.items = [] def isEmpty(self): return self items def push(self, item): self.items.append(item) def pop(self): return self.items.pop() det peek(self): return self.items[len(self.items)-1] def size (self): return len(self, items) 1. Motivating questions. a. Using the Stack class, what happens when you try to do a pop() operation on an empty Stack? b. Using the Stack class, what happens when you try to do a peek() operation on an empty Stack? 2. Create a new Stack class, called Stack2, and modify the following methods. a. pop() i. Return None when the stack is empty. b. peeko) i. Return None when the stack is empty. c. In your stack2.py source code file, add test functions and test code to test the modifications you made to each method. 3. Create a new Stack class, called Stack3, and modify the following methods. a. pop() 1. Raise an Exception when the stack is empty. Include an appropriate message to be displayed when the Exception is printed. The statement will look something like: raise Exception (appropriate message" b. peek() 1. Raise an Exception when the stack is empty. Include an appropriate message to be displayed when the Exception is printed. C. In your stack3.py source code file, add test functions and test code to test the modifications you made to each method 4. What files should you submit? a. Submit two Python source code files - stack2.py and stack3.py - as described in steps 2 and 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
