Question: Please use Python 3.8 Complete the push method for class SpecialStack . it has a maximum capacity and can only hold data of type 'int'.

Please use Python 3.8

Complete the push method for class SpecialStack.

it has a maximum capacity and can only hold data of type 'int'.

If the SpecialStack is already at full capacity, raise a StackFullException with the error message "Sorry. Maximum capacity reached".

Otherwise, if the item to be pushed is not an int, raise a TypeError with the message "Sorry. Only integers are permitted".

Make sure to define all necessary exceptions (if any).

You can implement SpecialStack with the top of stack at the right or the left.

Do not implement any extra methods. """

from __future__ import annotations from typing import List

# TODO Define any exceptions you need

class SpecialStack: """A last-in, first-out (LIFO) stack of int items and limited capacity."""

_data: List[int] _max_capacity: int def __init__(self: SpecialStack, max_capacity: int) -> None: """Initialize a new empty SpecialStack with max_capacity capacity.""" self._data = [] self._max_capacity = max_capacity def push(self: SpecialStack, item: int) -> None: """Place item on top of the stack. If the SpecialStack is already at full capacity, raise a StackFullException with the error message "Sorry. Maximum capacity reached". >>> s = SpecialStack(2) >>> s = SpecialStack(2) >>> #s.push('a') #... TypeError raised: Sorry. Only integers are permitted >>> s.push(2) >>> #s.push(3) #... StackFullException raised: Sorry. Maximum capacity reached """

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!