In Making The Grade exercise in Python, there are different exercises and I’m having trouble getting past Task 5.
Here is my code:
def student_ranking(student_scores, student_names):
"""Organize the student's rank, name, and grade information in descending order.
:param student_scores: list - of scores in descending order.
:param student_names: list - of string names by exam score in descending order.
:return: list - of strings in format ["<rank>. <student name>: <score>"].
"""
result_list = []
if len(student_scores) == len(student_names):
for index, word in enumerate(student_names):
numbering_string = str(index + 1)
index_string = str(word)
score_string = str(student_scores[index])
new_string = numbering_string + '. ' + word + ': ' + score_string
result_list.append(new_string)
return result_list
When I print the values inside the result_list, it prints as expected. But if I used the return syntax to pass the return list, it shows the error:
TypeError: list indices must be integers or slices, not list
I’m not sure why the error is that when I’m just returning the value and not accessing the items inside. This only occurs when I use the return syntax.