In the Array class of the arrays.py file complete the following: 1. Modify the __init__ method...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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() 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()
Expert Answer:
Answer rating: 100% (QA)
python class Arrayobject Represents an array def initself capacity fillValueNone selfl... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Based on the information in Problems 9 and 10, what is Ryan and Nicoles liquidity ratio? What is their debt to asset ratio? Comment on each ratio. In Problems 10 Mortgage......... $ 43,500 Car...
-
Emily owns a coal mine (basis $12,000 at the beginning of the year) that qualifies for a 15% depletion rate. Gross income from the property was $140,000, and net income before the percentage...
-
Find a least squares solution of Ax = b by constructing and solving the normal equations. -2 -3 |,b = A = 2 -2 3 4
-
What are the purpose and objectives of both external and internal audit, and what kind of service do they supply to management?
-
Assume that you have an after-tax cost of capital of 10 percent. Compute the net present value of each of the five projects listed in the following table. Rank the above projects from 1 (best for...
-
Balance sheet In millions ASSETS Current Assets Cash Trade recievables Inventories Income tax receivables Other current assests 2023 2022 2021 281.5 281.7 472.9 45.9 36.7 35.9 467.6 387.3 337 3 0.9...
-
Kelly Foods has two plants and ships canned vegetables to customers in four cities. The cost of shipping one case from a plant to a customer is given in the following table. The plant in Akron has a...
-
Multiple Choice Question Share draft accounts at a credit union: Multiple choice question. offer no liquidity. are no-interest bearing. are interest bearing. offer large interest rates.
-
What are some concerns that must be addressed to keep your visuals ethical?
-
What pattern of organization would you use for an informative or positive message?
-
What are some specific ways to choose effective images?
-
What are some strategies for building goodwill in your messages?
-
What are some best practices for organizing transmittals and summaries?
-
Each edge is annotated with the current flow (initially zero) and the edges capacity. In general, a flow of x along an edge with capacity y is shown as x/y. We will look at how the Ford-Fulkerson...
-
The percentage of completion and completed contract methods are described in the FASB ASC. Search the codification to find the paragraphs covering these topics, cite them, and copy the results.
-
Teresa is a civil engineer who uses her automobile for business. Teresa drove her automobile a total of 21,732 miles during 2012, of which 95 percent was business mileage. The actual cost of...
-
Frederick (Freddy) Freeweights (age 42) owns and operates a health club called ''Treadmills West.'' The business is located at 4321 Arnold Street, Alpine, CA 91901. Freddy had the following income...
-
Sally and Charles Heck received the following dividends and interest during 2012: Assuming the Hecks file a joint tax return, complete Schedule B of Form 1040 (on page 2-33) for them for the 2012 tax...
-
The salaries (in thousand dollars) of a sample of 10 employees Find the mean, the median, and the mode of the data, if possible. If any measure cannot be found or does not represent the center of the...
-
The durations (in minutes) of idle times at a factory in the last 10 months Find the mean, the median, and the mode of the data, if possible. If any measure cannot be found or does not represent the...
-
The numbers of weeks the 33 leading movies remained at number 1 as of March 2018. Find the mean, the median, and the mode of the data, if possible. If any measure cannot be found or does not...
Study smarter with the SolutionInn App