0
if __name__ == '__main__':

scores = [[8, 1], [5, 3], [3, 5], [8, 1], [7, 1], [1, 0], [9, 0], [5, 0], [6, 0], [8, 1, 0]]
#scores_int = 0;
#scores_int = len(scores);
sum = 0;


for row in range(len(scores)):
    sum = scores[0]
print(sum)
print(scores[0:1])
print(scores[1][0])
   #print("Sum of all all the socres:", sum);

So im trying to figure out a way to loop through every instance of the array and add the values in them to a sum variable, but i dont understand how to loop through a 2d array. The score sum should equal 72 i just need syntax help with the for loop

1 Answer 1

1

My advice if you're begginer is just to experiment with things you don't know. Next time you could print all the list of numbers and then try to sum it , avg it, or count the numbers inside it

if __name__ == '__main__':
    scores = [[8, 1], [5, 3], [3, 5], [8, 1], [7, 1], [1, 0], [9, 0], [5, 0], [6, 0], [8, 1, 0]]
    total = 0
    
    for list_of_number in scores:
        # print(list_of_number)
        total += sum(list_of_number)
    
    print(total)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Michael for your advice, and ive been experimenting for the past two days. I just hit a wall. Thank you for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.