In Python, matrices can be created using nested lists. For example, [[1, 2], [3, 4]]. Below I have written a function that prompts the user for the dimensions of a square matrix and then prompts the user for the values in the for loop. I have a tempArray variable that temporarily stores one row of values, and then is deleted after it is appended to the matrix array. For some reason, when I print the matrix at the end, this is what I get: [ [ ], [ ] ]. What is going wrong?
def proj11_1_a():
n = eval(input("Enter the size of the square matrix: "))
matrix = []
tempArray = []
for i in range(1, (n**2) + 1):
val = eval(input("Enter a value to go into the matrix: "))
if i % n == 0:
tempArray.append(val)
matrix.append(tempArray)
del tempArray[:]
else:
tempArray.append(val)
print(matrix)
proj11_1_a()
del tempArray[:]