Question: In the Array class of the arrays.py file complete the following: 1. Modify the __init__ method to add an instance variable logicalSize. o This

In the Array class of the arrays.py file complete the following: 1.

 Modify the __init__ method to add an instance variable logicalSize. o This variable is initially 0 and will track the number of items currently available to users of the array. 2. Define the size() method. o 

In the Array class of the arrays.py file complete the following: 1. Modify the __init__ method to add an instance variable logicalSize. o This variable is initially 0 and will track the number of items currently available to users of the array. 2. Define the size() method. o This method should return the array's logical size. o The method_len_should still return the array's capacity or physical size. To test your program run the main() method in the arrays.py file. Your program's output should look like the following: Physical size: 10 Logical size: 0 Items: [None, None, None, None, None, None, None, None, None, None] File: arrays.py Project 4.1 Adds a logical size attribute and a size method. An Array is a restricted list whose clients can use only [], len, iter, and str. To instantiate, use = array( , ) The fill value is None by default. class Array(object): ""Represents an array.""" def __init__(self, capacity, fillValue = None): This study source was downloaded by 100000774796243 from CourseHero.com on 06-07-2023 03:38:09 GMT-05:00 https://www.coursehero.com/file/176822404/Excerise-41docx/ """Capacity is the static size of the array. fillValue is placed at each position.""" self.logicalSize = 0 self.items = list() for count in range(capacity): self.items.append(fillValue) def size(self): return self.logicalSize def _len__(self): www->The capacity of the array.""" return len(self.items) def _str_(self): -> The string representation of the array."" return str(self.items) def __iter_(self): Supports traversal with a for loop.""" return iter(self.items) def getitem_(self, index): Subscript operator for access at index.""" return self.items[index] def _setitem_(self, index, newltem): Subscript operator for replacement at index.""" self.items[index] = newltem def main(): "Test code for modified Array class." a = Array(10) def main(): """Test code for modified Array class.""" a = Array(10) print("Physical size:", len(a)) print("Logical size:", a.size()) print("Items:", a) if __name__ == "__main__": This study source was downloaded by 100000774796243 from CourseHero.com on 06-07-2023 03:38:09 GMT-05:00 https://www.coursehero.com/file/176822404/Excerise-41docx/ main()

Step by Step Solution

3.32 Rating (149 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

python class Arrayobject Represents an array def initself capacity fillValueNone selfl... 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!