def get_class_average(students):

results =

for student in students:

get_average(student)

results.append(get_average(student))

return average(results)

My code is exactly the same as the one posted here, but it does not work.

my code:

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)

total = float(total)

mean = total / len(numbers)

return mean

def get_average(student):

homework = average(student[âhomeworkâ])

quizzes = average(student[âquizzesâ])

tests = average(student[âtestsâ])

return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

def get_letter_grade(score):

if score >= 90:

return âAâ

elif score >= 80:

return âBâ

elif score >= 70:

return âCâ

elif score >= 60:

return âDâ

else:

return âFâ

print get_letter_grade(get_average(lloyd))

def get_class_average(students):

results =

for student in students:

get_average(student)

results.append(get_average(student))

return average(results)

Can you please post the message you received?

Also, can you enclose your code in backticks so it is properly formatted?

^ These are backticks.

Put three backticks on the line before your code.

Put three more backticks on the line after your code.

@papayabubble: What answer runs properly when I try it. Are you receiving an error message? If so, what does it say?

In terms of advice, Iâd just ask: Why include this line? What does it do for you? Do you lose anything if you remove it from your code?

You need to use:

get_average(student)

because for a class average you need to add the averages from the different students. If you donât put it in your class average wonât have any numbers to work on. Get it?

Youâre right the you need to do that at some point, but you do it twice.

[quote=âpapayabubble, post:1, topic:25687â]`get_average(student) results.append(get_average(student))`

[/quote]

Do you need the first instance?

You donât need it the first time but I put it in there to understand which step Iâm at compared to the instructions.

Did you make sure your indentation was correct?

Or you can otherwise you could try it like this:

def get_class_average(students):

results =

for student in students:

results.append(get_average(student))

return average(results)

I tried and it does not work!

The reply of the system is: ââOops, try again. get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expectedââ

Write only the last method

I hope this will help you guys:

def get_class_average(students):

âŚresults =

âŚfor item in students:

âŚget_average(item)

âŚresults.append(get_average(item))

âŚreturn average(results)

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]

}

# Add your function below!

def average(numbers):

total= sum(numbers)

total=float(total)

return total/len(numbers)

def get_average(student):

homework=average(student[âhomeworkâ])

quizzes=average(student[âquizzesâ])

tests=average(student[âtestsâ])

return 0.1*homework+0.3*quizzes+0.6 *tests

def get_letter_grade(score):

if score>=90:

return âAâ

elif score>=80:

return âBâ

elif score>=70:

return âCâ

elif score>=60:

return âDâ

else :

return âFâ

print get_letter_grade(get_average(lloyd))

def get_class_average(students):

results=

x=get_average(students[0])

y=get_average(students[1])

z=get_average(students[2])

results.append(x)

results.append(y)

results.append(z)

q=average(results)

return (x,y,z,q)

plz help me where i am goining wrong

error is Oops, try again. get_class_average([alice]) resulted in an error: list index out of range

I got the same error message. Then I adjusted the indentation on the last line of code and it compiled properly.

iâve fix it try this code :

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 = float(sum(numbers))

result = total / float(len(numbers))

return result

#def get_average(lloyd,alice,tyler):

def get_average(student):

lloyd_homework=average(student[âhomeworkâ])

lloyd_quizzes=average(student[âquizzesâ])

lloyd_tests=average(student[âtestsâ])

lloyd_average_score=0.1*lloyd_homework+0.3*lloyd_quizzes

+0.6*lloyd_tests

return lloyd_average_score

n = lloyd

print get_average(n)

def get_letter_grade(score):

if(score >= 90.0):

return âAâ

elif score >= 80.0:

return âBâ

elif score >= 70.0:

return âCâ

elif score >= 60.0:

return âDâ

else:

return âFâ

print get_letter_grade(get_average(lloyd))

students = [lloyd,alice,tyler]

def get_class_average(students):

results =

for item in students:

results.append(get_average(item))

```
return average(results)
```

Thank you for your kind cooperation. The key is to actually fix the indentation in the last line of code, stepping back âreturnâ.

papayabubble, you are teaching yourself to write redundant code. This is messy and may cause issues on future assignments. You should comment out any redundant code that you write if you are going to leave it in to follow the instructions.