Question: python 3, first_divisible def first_divisible(mat, d=2): divisible_indices = [] first_element = mat[0] index = 0 for element in first_element: if(element%d==0 or d%element==0): divisible_indices.append(index) index+=1 if(divisible_indices):
python 3, first_divisible
![python 3, first_divisible def first_divisible(mat, d=2): divisible_indices = [] first_element = mat[0]](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66efdefec57c9_22266efdefe63706.jpg)
def first_divisible(mat, d=2):
divisible_indices = []
first_element = mat[0]
index = 0
for element in first_element:
if(element%d==0 or d%element==0):
divisible_indices.append(index)
index+=1
if(divisible_indices):
return divisible_indices
else:
return None
I tried this but it doensn't work. It returns 0. But it should return[0,0]
first divisible: This function takes a nonempty integer numpy matrix and an integer with default value of 2 and returns a list or a 1-D array containing the indices of the first element divisible by the second argument. Your outer loop should go down the rows. If no element is divisible by the integer, return None. For instance, if the matrix is [[1, 2, 9], [7, 11, 13]] and the second argument is 3, the function should return [0, 2]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
