Question: Python Can you please help edit the code below? I want to make a function where it checks if the number is greater than the

Python Can you please help edit the code below? I want to make a function where it checks if the number is greater than the next number in a 2D array. If it is, the count will increase by 1. puzzle = [[1, 2, 3],[4, 5, 6],[8, 7, 0]] For the 2D array above, the count should print '1'

def getInvCount(puzzle) :

inv_count = 0

for i in range(len(puzzle)):

for j in range(len(puzzle[i])):

#print(puzzle[i][j])

if (puzzle[i][j] > (puzzle[i][j] + 1)):

inv_count += 1

print (inv_count)

return inv_count

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!