Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having trouble with this problem, and the solution on chegg isn\'t coming w

ID: 3711433 • Letter: I

Question

I'm having trouble with this problem, and the solution on chegg isn't coming with correct indentation in python. Thank you.

**11.19 (Pattern recognition: four consecutive equal numbers) Write the following function that tests whether a two-dimensional list has four consecutive numbers of the same value, either horizontally, vertically, or diagonally def ?sConsecutiveFour(values) : Write a test program that prompts the user to enter the number of rows and columns of a two-dimensional list and then the values in the list. The pro- gram displays True if the list contains four consecutive numbers with the same value; otherwise, it displays False. Here are some examples of the True cases: 010316 0168601 016860 016860 0103161 0103161 010316 0168601 5 6 2 18 29 5521829 562 1629 9 621829 656119 13 61407 1 5 61407 1 3 61 4071391407 3 3 3 3 4 0 7 6 5619 65661916 961 91 3533407 3633 407 3 3394 0 7

Explanation / Answer

def isConsecutiveFour(values):
columns = len(values)
rows = len(values[0])
  
for i in range(0, rows):
for j in range(0, columns-3):
if (values[j][i] == values[j+1][i] and values[j][i] == values[j+2][i] and values[j][i] == values[j+3][i]):
return True
  
for i in range(0, rows-3):
for j in range(0, columns):
if (values[j][i] == values[j][i+1] and values[j][i] == values[j][i+2] and values[j][i] == values[j][i+3]):
return True
  
for i in range(3, rows):
for j in range(0, columns-3):
if (values[j][i] == values[j+1][i-1] and values[j][i] == values[j+2][i-2] and values[j][i] == values[j+3][i-3]):
return True

for i in range(0, rows-3):
for j in range(0, columns-3):
if (values[j][i] == values[j+1][i+1] and values[j][i] == values[j+2][i+2] and values[j][i] == values[j+3][i+3]):
return True
return False

row = int(input("Enter number of rows: "))
col = int(input("Enter number of columns: "))

values = []
for i in range(row):
row_vals = []
for j in range(col):
row_vals.append(int(input("Enter value arr[" + str(i+1) + "][" + str(j+1) + "]: " )))
values.append(row_vals)
if isConsecutiveFour(values):
print("There are 4 consecutive same values")
else:
print("There are no 4 consecutive same values")

# copy pastable code: https://paste.ee/p/yuOIw

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote