Help with the function


Hi, I get the answer but without the use of methods in the instructions. May I know who has solved the problem? My code is :

for s in students :
homework = average (s["homework"])
quizzes = average (s["quizzes"])
tests = average (s["tests"])
weighted_average = 0.1*homework + 0.3*quizzes + 0.6*tests
print weighted_average
students = [lloyd, alice, tyler]

I tried using the instructions but I just cannot get the answer.

I have tried to use function as instructed. This is my answer :
def get_average(student):
for s in student :
homework= average (s["homework"])
quizzes= average (s["quizzes"])
tests= average (s["tests"])
weighted_average = 0.1 *(homework) + 0.3 *(quizzes) + 0.6 * (tests)
return weighted_average
student = [lloyd, alice, tyler]

I get the error : get_average(alice) raised the following error: string indices must be integers, not str

Does coding really takes so much time to get the correct answer? I have used a few hours but to no avail.


Please present ALL of your code....
and if you do present the code, put it in the < pre-code> state
using the </>-button of this editor....

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.