I am making a function that checks if my square is a Lo Shu Magic Square. Thus I have to have the sum of each row, each column, and each diagonal all add up to the same number.

NUMBERS = [[1,2,3],[4,5,6],[7,8,9]]

def checkMagicBox(box):

  isBool = True
  magicNumber = 0
  for idx in range(3):
    magicNumber += box[idx][idx]
  print(magicNumber)


  totalDiag = 0
  for idx in range(3):
    totalDiag += box[idx][2-idx]
  print(totalDiag)

  isBool = magicNumber == totalDiag

  if isBool:
    for line in range(3):
      print(sum(box[line]))

  if isBool:
    for col in range(3):
      totalCol = 0
      for line in range(3):
        totalCol += box[line][col]
      print(totalCol)

  return isBool

def main():
    print(checkMagicBox(NUMBERS))

main()    

My problem is that my function should be showing true when it is supposed to be not true.

1 Answers

0
Amit Nanaware On

In your code expression magicNumber == totalDiag is True so it is returning true. You can debug your code and check the values