Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following file with triangular data, if you will Run the next set of four cells to create the data files that will be
Consider the following file with "triangular" data, if you will Run the next set of four cells to create the data files that will be needed in the test cases further below ( data_1.dat - data_4.dat). In [ ]: file data_1.dat 23 4 5 6 7 8 9A BCDEF G H I J K L In [ ]: **file data_2.dat 1 2 3 4 5 6 7 8 9 A BCDEF G H I J K L M In [ ]: #file data_3.dat a bc d g hij klmnc pqrstu In [ ]: file data_4.dat 1 2 3 4 5 6 7 8 9 Now consider the following ADT named triangular: triangular( data_filepath, data_converter=str ): initializes a triangular object with the data provided in a file at data_filepath. Each row of data will be stored as a list of values converted to the data format that will be specified by the data_converter parameter, which must be a function that takes single parameter. The default value of data converter function is str. That is, the data converter will be called on each piece of data to do the conversion. The data will be stored as a list of sublists in an instance variable called data If the input data is not triangular, the initializer method should raise a ValueError. For example, the content of data_1.dat should be represented as [['i'i ['2', '3'), ['4', '5', '6'), ['7', '8', '9', 'A'), ['B', 'C', 'D', 'E', 'F'], ['G', 'H', 'I', 'J', 'K', 'L']] in memory len( triangular( ... )) should return the number of rows in the data. In data_1.dat, there are 6 rows, for example. triangular.check() should return True if the input data specified for the initializer above is indeed triangular in shape. . a + b should return the addition of two triangular objects, a and b, depending on their type. Assume that a and b will always be compatible. If the dimensions of a and b are not identical, this method should raise an AssertionError. Implement this ADT in Python PROVIDE YOUR ANSWER IN THE FOLLOWING CODE CELL In (: # YOUR CODE HERE raise Not ImplementedError() In [ ]: # WARNING! # data If you have not defined an instance field named all remaining tests will fail! in your triangular class, 4 4 # Please follow the provided specifications! # + t = triangular( 'data_1.dat' ) "data" in dir( t.data) assert hasattr(t, 'data' ), "Your triangular instance should have a 'data' field as specified!" Consider the following file with "triangular" data, if you will Run the next set of four cells to create the data files that will be needed in the test cases further below ( data_1.dat - data_4.dat). In [ ]: file data_1.dat 23 4 5 6 7 8 9A BCDEF G H I J K L In [ ]: **file data_2.dat 1 2 3 4 5 6 7 8 9 A BCDEF G H I J K L M In [ ]: #file data_3.dat a bc d g hij klmnc pqrstu In [ ]: file data_4.dat 1 2 3 4 5 6 7 8 9 Now consider the following ADT named triangular: triangular( data_filepath, data_converter=str ): initializes a triangular object with the data provided in a file at data_filepath. Each row of data will be stored as a list of values converted to the data format that will be specified by the data_converter parameter, which must be a function that takes single parameter. The default value of data converter function is str. That is, the data converter will be called on each piece of data to do the conversion. The data will be stored as a list of sublists in an instance variable called data If the input data is not triangular, the initializer method should raise a ValueError. For example, the content of data_1.dat should be represented as [['i'i ['2', '3'), ['4', '5', '6'), ['7', '8', '9', 'A'), ['B', 'C', 'D', 'E', 'F'], ['G', 'H', 'I', 'J', 'K', 'L']] in memory len( triangular( ... )) should return the number of rows in the data. In data_1.dat, there are 6 rows, for example. triangular.check() should return True if the input data specified for the initializer above is indeed triangular in shape. . a + b should return the addition of two triangular objects, a and b, depending on their type. Assume that a and b will always be compatible. If the dimensions of a and b are not identical, this method should raise an AssertionError. Implement this ADT in Python PROVIDE YOUR ANSWER IN THE FOLLOWING CODE CELL In (: # YOUR CODE HERE raise Not ImplementedError() In [ ]: # WARNING! # data If you have not defined an instance field named all remaining tests will fail! in your triangular class, 4 4 # Please follow the provided specifications! # + t = triangular( 'data_1.dat' ) "data" in dir( t.data) assert hasattr(t, 'data' ), "Your triangular instance should have a 'data' field as specified
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started