def matrixADD(A,B):
minilist=[]
Z = []
a=-1
b=-1
The condition in while loop below is not being followed for some reason so the index goes out of range. To fix it I had to add nested if statement below to break out of the loop. It is very weird I was wondering why is it not working without the if statement?
while len(A)!=len(Z):
x=-1
y=-1
a=a+1
b=b+1
if len(minilist)!=0:
Z.append(minilist)
if len(A)==len(Z):
break
minilist=[]
while len(A[a])!=len(minilist):
for numbers in A[a]:
x=x+1
y=y+1
answer=(A[a][x]+B[b][y])
minilist.append(answer)
return Z
def main():
#Test matrices
A = [[2,4], [7,0], [6,3]]
B = [[3,1], [-1,8], [-3, 3]]
Z=matrixADD(A,B)
print("A + B:",Z)
main()
Hi guys. I wrote this program and it works just fine but I was having some trouble with 1 thing (indicated above)
Thanks for your input guys :)
Ais, for god sakes, and why we want to repeat doing stuff to it untilminilistis as long as it!for element in iterable. Don't do that in Python. Tell us what you're trying to accomplish and it will work a whole lot better than trying to fix a bad implementation of it