8. part of the whole


#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]
}

Add your function below!

def average(numbers):
total = sum(numbers)
total = float (total)
total = total/len(numbers)
return total
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
sum = homework * 0.1 + quizzes * 0.3 + tests * 0.6
return sum
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"
get_letter_grade(lloyd)
students = ["alice","lloyd","tyler"]
def get_class_average(students):
results = []
for student in students:
get_average(student)
results.append(get_average(student))
return average

error message: "
Oops, try again. get_class_average([alice]) should return a numbe"


#2

You wrote:
students = ["alice","lloyd","tyler"]
Student names should't be strings, they should point to the dictionaries. just write names without " ".


#3

i am facing same problem!! what to do?


#4

You shouldn't define the list Students. I believe you miss read the instructions. 03: For each student item in the class list, calculate get_average(student) and then call results.append() with that result. The instructions where trying to emphasize that you iterate through the class_list or in your case the list students.

Also in future please show your code with proper formatting i.e. indentations, white space, etc. This makes your code more readable and is how code should be written. Especially in python as it works based on white space.


#5

I think the solution to the error is your ending with return average

should be return average(results)

still havent gotten mine to completely work though


#6
`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)
    print total
    total = float(total)
    total = total/len(numbers)
    return total
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    homework2 = homework*0.10
    quizzes2 = quizzes*0.30
    tests2 = tests*0.60
    final = homework2+quizzes2+tests2
    return final
    
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 = [alice,lloyd,tyler]
def get_class_average(students):
    results = []
    for student in students:
        get_average(student)
        results.append(get_average(student))
    return average`

Someone spot the error and correct?


#7

You should be returning the class average, so it is the average of the results list. In your code, you are returning a variable called average, which is incorrect. Also I don't think the tilde does anything.


Part of the whole-8
#9

A post was split to a new topic: Unsupported operand type


#10

looks like you have 'lloyd and not lloyd at the top of your screen? some random single quote there?


#11

That is markdown for code sample phrase. The post should use three backticks, not one before and after code.


#12

Would it not be the same thing with the list "Students"? Do we need to create a list called "Class"?`


#13

The instructions explicitly ask for a list called students, and that is all we need. It should contain just a list of references to each student dictionary.

students = [ lloyd, alice, tyler ]

Notice there are no quotes. These are object references (variables).

The member posted the correct solution to the OP.