Jan-16-2019, 10:24 PM
N = 3 # Returns true if square is magic # square, else returns false. def is_magic(square): # calculate the sum of # the prime diagonal sum = 0 for i in range(0, N): sum += square[i][i] # For sums of Rows for i in range(0, N): rowSum = 0 for j in range(0, N): rowSum += square[i][j] # check if every row sum is # equal to prime diagonal sum if (rowSum != sum): return False # For sums of Columns for i in range(0, N): columnSum = 0 for j in range(0, N): columnSum += square[j][i] # check if every column sum is # equal to prime diagonal sum if (sum != columnSum): return False return True str_input = input("write a squence of nine numbers") str_list = str_input.split() square = [] for i in range(0, N): square.append([]) for j in range(0, N): square[i].append(int(str_list[j + i * N])) if (is_magic(str_list)): print("This is Magic Square") else: print("This is Not a magic Square")The error I keep getting is in the line where it says
square[i].append(int(str_list[j + i * N]))
I am trying to create a program that asks user for sequence of 9 numbers and determines if they are nagic square or not.