Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

Students also viewed these Databases questions