Question: using python 3 how should I define the function In an earlier in-class exercise, we defined a function to extract a certain column's value from

 using python 3 how should I define the function In anusing python 3 how should I define the function
earlier in-class exercise, we defined a function to extract a certain column's

In an earlier in-class exercise, we defined a function to extract a certain column's value from a single line of a file. We can make that slightly more general by adding a parameter to the function that allows us to specify which column we want to extract. This function is more useful, because it can be reused to extract numeric value from any column, not just one particular column. Define a function named get_number() that extracts a number from a given line in a specific column with the following specification that extracts a number from a g It has two parameters The first parameter is a string containing one line from a CSV file (ie, a string with column entries separated by, characters) . The second parameter is an integer specifying which column from that line you want to get If the given line does not contain enough entries to have a value in the specified column, the function should return None. If the value in the specified column is not numeric, the function should return None. You can use the string method .isnumeric() to determine if a string contains a numeric value or not . Otherwise, the function should return the number in the specified column as a float (13]: Define the get number() function here. def get_number(line, index): if return None if linelindex].isnumeric return return value Tests Executing the cell below will run some tests on the get_nunber() function you define above. It passes a variety of lists and column numbers to the function The expected return values for the first three are shown here, and you should think about what the others should be to verty that your function is passing all of the tests. ine: 1,2,3,A,B,c. index: 1 return value: 2.e ine: 123,ABC index: 3 return value: None +&C Code the tests. First three expected test outputs: line : '1,2,3,A,B,C '1,2,3,A,B,C, '123,ABC, index : ndex: 3 1 return value : 2.e 3 return value : None return value : None line: line : ndex : . [15]: # Tests for get-number() [do not modify] test line 1 "1,2,3,A,B,c test line_2 "123,ABC" test_line 3 ret get_number(test_line 1, 1) print(line: index: return value:(".format (repr(test_line1), 1, ret)) ret- get_ number(test line 1, 3) print("line: index: (return value: (".format repr(test, line 1), 3, ret)) ret- get number(test_line 2, 3) print("line: {} index: {} return value: --format (repr(test-i ine-2), s, ret) ret- get_number(test lime 2, e) print("1ine: index: ) return value: " format (repr(test line-2), e, ret) ret-get_number(test_line 2, 1) print("line: ( index: return value: (". format (repr(test_line_2), 1, ret)) ret - get number(test_line_3, 8) print("line: ) index: return value: (".fornat (repr(test_line3), e, ret) print("line: index: ) return value: ()".format (repr(test line_3), 1, ret)) line : line: line: '1,2,3,A,B,C, ndex: 1 return value: '1,2,3,A,B,C ndex: 3 return value : .123,ABC, ndex: 3 return value : , , line: '123 ,ABC ndex:e return value:1 ine: '123,ABC' index: 1 return value: 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!