# String indices must be integers, not str

#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
Traceback (most recent call last):
File “python”, line 51, in
File “python”, line 47, in get_class_average
File “python”, line 26, in get_average
TypeError: string indices must be integers, not str

<What do you expect to happen instead?>
To take the student list

```python

lloyd = {
“name”: “Lloyd”,
“homework”: [90.0, 97.0, 75.0, 92.0],
“quizzes”: [88.0, 40.0, 94.0],
“tests”: [75.0, 90.0]
}
alice = {
“name”: “Alice”,
“homework”: [100.0, 92.0, 98.0, 100.0],
“quizzes”: [82.0, 83.0, 91.0],
“tests”: [89.0, 97.0]
}
tyler = {
“name”: “Tyler”,
“homework”: [0.0, 87.0, 75.0, 22.0],
“quizzes”: [0.0, 75.0, 78.0],
“tests”: [100.0, 100.0]
}

def average(numbers):
total=sum(numbers)
return float(total)/len(numbers)
for d in c:
homework=average(d[“homework”])
quizzes=average(d[“quizzes”])
tests=average(d[“tests”])
return 0.1homework+0.3quizzes+0.6*tests

if score>=90:
return "A"
elif score>=80:
return "B"
elif score>=70:
return "C"
elif score>=60:
return "D"
else :
return “F”

def get_class_average(b):
results=[]
for a in b:
results.append(get_average(a))
return results

student=[lloyd,alice,tyler]
print (get_class_average(student))

``<do not remove the three backticks above>``

#2

Somehow the copyright symbol got inserted in the code.

``````def get_average(student):
``````

You can drop that loop.

#3

Oh! I forgot droping the loop. Thanks a lot. It helped.

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.