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
Recommended Answers
Jump to Post4c4,5 < x = x + M[i][i] --- > for j in range(3): > x = x + M[i][j]
4c4 < for j in range(3): --- > for j in range(i): 6c6 < print x --- > print x \ No newline at end …
All 2 Replies
Reply to this topic
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.