M = [[1,2,3], [4,5,6], [7,8,9]]
x=0
for i in range(3):
x = x + M[i][i]
print x
-------
M = [[1,2,3], [4,5,6], [7,8,9]]
x=0
for i in range(3):
for j in range(3):
x = x + M[i][j]
print x
----------
M = [[1,2,3], [4,5,6], [7,8,9]]
x=0
for i in range(3):
for j in range(i):
x = x + M[i][j]
print x
Tops 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.