This is for my IT class, i am trying to find the sum of each row. Its a magic square program. when i run this it says int object not iterable. Also the teacher wants the header of the function like this def rowSum(matrix, rowNum) but i dont understand why rowNum would be needed. The function should be able to calculate the sum of each row of any size matrix. Also i cant use numpy and enumarate as we have not talked about it in class yet.
Matrix txt file:
1 4
3 2
Here is code
def main():
filNam = "matrix1.txt"
matrix = (readMatrix(filNam))
print(eachNumPresent(matrix))
print(rowSum(matrix))
def readMatrix(filNam):
matrixFile = open(filNam, "r")
line = matrixFile.readline()
for line in matrixFile:
line = line.split()
return line
matrixFile.close()
def eachNumPresent(matrix):
if len(matrix) % 2 == 0:
return True
else:
print("Not enough numbers")
def rowSum(matrix, rowNum):
for line in matrix:
return(sum(int(line)))
main()