Do Someone know the reason ot the code stays wrong? The error happens because the matrix's index | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Do Someone know the reason ot the code stays wrong? The error happens because the matrix's index

https://code.sololearn.com/cVHV8SHd6C1N/?ref=app

18th Nov 2018, 12:11 PM
Gabriel Felix dos Santos
Gabriel Felix dos Santos - avatar
3 Answers
+ 3
Basically the code is trying to assign values at a list location that it doesn't have yet. For the same reason something like the following won't work a = [] a[0] = 1 To add new entries, we use the list.append method. One way to fix your code is this: for line in range(0, lines): matrix.append([]) # adds a new row for column in range(0, columns): matrix[line].append(rand(0, 100))
18th Nov 2018, 12:23 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
You're welcome! :)
18th Nov 2018, 1:12 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
Thank you so much ✌✌
18th Nov 2018, 1:02 PM
Gabriel Felix dos Santos
Gabriel Felix dos Santos - avatar