How can I sum each list within a nested list using a Python function?

I have a random set of test scores for 50 students. Each student answered 20 questions, and the maximum score for each question is 5. How can I get the total score of each student in a list by using a Python function?

results_sheet = []
num_of_questions = 20
num_students = 50

#generate scores for each student and append to results_sheet

for student in range(num_students):
        scores = random.choices(list(range(0,6)),k=num_of_questions)
#The result here is a list of lists.

I have tried the following code but am missing something:

total = 0
for val in results_sheet:
    total = total + val
return total  

Thank you very much.

Read more here:

Content Attribution

This content was originally published by CTan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: