Question: a function that receives a one-dimensional array of integers and returns a Python tuple with two values - the minimum and maximum values of the

a function that receives a one-dimensional array of integers and returns a Python tuple with two values - the minimum and maximum values of the input array. The content of the input array must not be changed. You may assume that the input array will contain only integers, and will have at least one element. You do not need to check for these conditions. For full credit, the function must be implemented with O(N) complexity

Write a function that receives a one-dimensional array of integers and returns

class StaticArrayException(Exception):
    """
    Custom exception for Static Array class.
    Any changes to this class are forbidden.
    """
    pass


class StaticArray:
    """
    Implementation of Static Array Data Structure.
    Implemented methods: get(), set(), length()

    Any changes to this class are forbidden.

    Even if you make changes to your StaticArray file and upload to Gradescope
    along with your assignment, it will have no effect. Gradescope uses its
    own StaticArray file (a replica of this one) and any extra submission of
    a StaticArray file is ignored.
    """

    def __init__(self, size: int = 10) -> None:
        """
       array of given size.
        Initialize all elements with values of None.
        If requested size is not a positive number,
        raise StaticArray Exception.
        """
        if size             raise StaticArrayException('Array size must be a positive integer')

        # The underscore denotes this as a private variable and
        # private variables should not be accessed directly.
        # Use the length() method to get the size of a StaticArray.
        self._size = size

        # Remember, this is a built-in list and is used here
        # because Python doesn't have a fixed-size array type.
        # Don't initialize variables like this in your assignments!
        self._data = [None] * size

    def __iter__(self) -> None:
        """
        Disable iterator capability for StaticArray class.
        This means loops and aggregate functions like
        those shown below won't work:

        arr = StaticArray()
        for value in arr:     # will not work
        min(arr)              # will not work
        max(arr)              # will not work
        sort(arr)             # will not work
        """
        return None

    def __str__(self) -> str:
        """Override string method to provide more readable output."""
        return f"STAT_ARR Size: {self._size} {self._data}"

    def get(self, index: int):
        """
        Return value from given index position.
        Invalid index raises StaticArrayException.
        """
        if index = self.length():
            raise StaticArrayException('Index out of bounds')
        return self._data[index]

    def set(self, index: int, value) -> None:
        """
        Store value at given index in the array.
        Invalid index raises StaticArrayException.
        """
        if index = self.length():
            raise StaticArrayException('Index out of bounds')
        self._data[index] = value

    def __getitem__(self, index: int):
        """Enable bracketed indexing."""
        return self.get(index)

    def __setitem__(self, index: int, value: object) -> None:
        """Enable bracketed indexing."""
        self.set(index, value)

    def length(self) -> int:
        """Return length of the array (number of elements)."""
        return self._size

    @property
    def size(self):
        return self._size


if __name__ == "__main__":

    # Using the Static Array #

    # Can use either the get/set methods or [] (bracketed indexing)         #
    # Both are public methods; using the [] calls the corresponding get/set #

    # StaticArray object - is the default size
    arr = StaticArray()

    # These two statements are equivalent
    arr.set(0, 'hello')
    arr[0] = 'hello'

    # These two statements are equivalent
    print(arr.get(0))
    print(arr[0])

    # Print the number of elements stored in the array
    print(arr.length())

    # new StaticArray object to store 5 elements
    arr = StaticArray(5)

    # Set the value of each element equal to its index multiplied by 10
    for index in range(arr.length()):
        arr[index] = index * 10

    # Print the values of all elements in reverse order
    for index in range(arr.length() - 1, -1, -1):
        print(arr[index])

    # Special consideration below #

    # Don't! This built-in Python list and if you use
    # one you'll lose points.
    forbidden_list = [None] * 10

    print(type(arr))
    print(type(forbidden_list))

Write a function that receives a one-dimensional array of integers and returns a Python tuple with two values the minimum and maximum values of the input array. The content of the input array must not be changed. You may assume that the input array will contain only integers, and will have at least one element. You do not need to check for these conditions. For full credit, the function must be implemented with O(n) complexity. Example #1: arr StaticArray (5) for i, value in enumerate ([7, 8, 6, -5, 4]): arr[i]= value print (arr) result min_max (arr) if result: print (f"Min: (result [0]: 3), Max: (result [1]}") print ("min_max () not yet implemented") else: Output: STAT_ARR Size: 5 [7, 8, 6, -5, 4] Min: -5, Max: 8

Step by Step Solution

3.49 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

def findminmaxarr if lenarr 1 re... View full answer

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 Programming Questions!