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...
-
Jerry, who is single with no dependents and does not itemize, provides you with the following information for the tax year. Short-term capital loss...
-
Ethical relativism suggests that what is ethical in one culture may not be considered ethical in another. What should the attitude of businesses be when differences occur? Should businesses follow...
-
True or False: If \(E R R>M A R R\), then MIRR \(>\) MARR.
-
Stellar Inc. is a construction company specializing in custom patios. The patios are constructed of concrete, brick, fiberglass, and lumber, depending upon customer preference. On June 1, 2012, the...
-
Is discord supported by a relational database, hierarchical database, NoSQL database, or something else?Explain
-
Provide the following for the following challenge exercise: a) Income Statement, Gross Margin Standard, year-to-date b) All Journal Entries c) Customer Aged Detail, all customers, with terms at Mar...
-
Shanthi Pharmaceuticals Ltd manufactures high-quality antibiotics for the healthcare sector. We are given that the variable materials cost is Rs. 2550 per kg, and the variable labor cost is Rs. 840...
-
In the Winter v. Gardens Regional Hosp. & Med. CTR, 2020 case who are the parties to the lawsuit and what is their dispute. What is the basic legal question regarding what specific provision of law...
-
The content that shows up on the Publisher's website but is available free of cost and can be helpful to improve SEO can be referred to as: Group of answer choices Display Ads Sponsored Ads Native...
-
Explain the principles behind virtual memory management in modern operating systems, including concepts such as demand paging, page replacement algorithms, and address translation techniques.
-
Discuss and analyze the purpose and importance of data preparation with regards to time series analysis. What are some indications that a dataset needs additional preparation?
-
Please I need the most 5 important opportunities and threats for Giant Consumer Products Case Opportunities: 1- 2- 3- 4- 5- Threats: 1- 2- 3- 4- 5-
-
37. In Problem 9.32, if the coefficient of friction between the rod and the floor is 4, calculate (a) the borizontal and vertical components of the reaction as a function of angle 0, (b) the angle at...
-
Sue Deliveau opened a software consulting firm that immediately paid $2,000 for a computer. Was this event a transaction for the business?
-
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...
-
Assume that the economy can experience four possible states: high growth, normal growth, recession, or depression. For each of those states, you expect the following stock market returns for the...
-
Suppose an investment pays off $800 or $1,600 with equal probability per $1,000 invested. What is the maximum leverage ratio you could have and still have enough to repay the loan in the event the...
-
The imposition of new trade tariffs has resulted in tensions between the United States and some of its major trading partners. Suppose you are a small business owner in the United States. a. How...
Study smarter with the SolutionInn App