I am currently trying a mathematics and computing course and hit a snag. The question I have been asked to produce a program for is:
Write a program to store the contents of a 6 by 6 matrix. The matrix M has been defined such that the value of the ith and jth column of the matrix is the result of multiplying i and j.
The JavaScript code is below:
var m = new Array();
var i,j;
for (i=0;i<6;i++){
m[i]=new Array(6);
for (j=0;j<6;j++){
m[i][j]=(i+1)*(j+1);
}
}
print m
My question is what would the same code look like in Python. I have tried the program below but hit with type and assignment errors.
m=[]
i=0
j=0
for i in xrange (6):
m.append(i)
for j in xrange (6):
m[i][j]=((i+1)*(j+1))
print m
Any help would be greatly appreciated.