# 8/9 Student becomes teacher

#1

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)
float(total)
length = len(numbers)
float(length)
result = float(total) / length
return result

def get_average (student):
homework = (average(student["homework"]) * .10)
quizzes = (average(student["quizzes"]) * .30)
tests = (average(student["tests"]) * .60)
return homework + quizzes + tests

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

students = [lloyd, alice, tyler]
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)

The error code received is ;
Oops, try again. get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected

What am i missing?

#2

@marutovic,
Tried your code in a windows 8.1 IE11 environment and got a pass....

``````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) )
#float(total)
length = float( len(numbers) )
#float(length)
#result = float(total) / length
result = total / length
return result``````

``````def get_average (student):
homework = (average(student["homework"]) * .10)
quizzes = (average(student["quizzes"]) * .30)
tests = (average(student["tests"]) * .60)
return homework + quizzes + 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))
students = [lloyd, alice, tyler]``````

``````def get_class_average(students_list):
results_list = []
for student in students_list:
print student
results_list.append(get_average(student))
#End of FOR-loop
#You now have a results_list with len(results_list) Elements
#we will return the =average= of the VALUES in the results_list
#print results_list
return average(results_list)``````

``````#Call the =get_class_average= function with =students= as ARGUMENT
#as the function-call will =return= a VALUE with no-display
#we use the =print=
print get_class_average( students )``````

``print get_letter_grade( get_class_average(students) )``

#3

Thank you for taking the time to help me, it is most appreciated. However I don't understand what i need to change in order to pass the task?

#4

I see what you did.
The indentation was wrong for return average. Thank you

#5

I don't want to open another Thread, so maybe can help me here.
The error massage I receive is: Oops, try again. get_class_average([alice]) resulted in an error: list indices must be integers, not str

I have writen the same program in Pycharm and it is running smoothly. I do not get why it is running in Pycharm and not here.

Here's 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)
total = total/len(numbers)

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
ergebnis = homework*0.1+quizzes*0.3+tests*0.6
return ergebnis

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(students):
results = []

for n in students:
print (n)
results.append(get_average(n))
print (results)

return average(results)``````

#6

Have you tried a reset Browser

++++ reset of session *****************
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Then use the Reset Code button of the course-window,
then paste your code back in.

General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom

#7

here is the code I used to finish it.
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)
total = total / len(numbers)

def get_average(student):
homework = average(student['homework'])
homework = average(student['quizzes'])
homework = average(student['tests'])
return .1 * average(student['homework']) + 0.3 * average(student['quizzes']) \
+ 0.6 * average(student['tests'])

if score >= 90.00:
return "A"
elif score >= 80.00:
return "B"
elif score >= 70.00:
return "C"
elif score >= 60.00:
return "D"
else:
return "F"