Just Weight & See: Error


#1

I have working code for this section. I receive an error message that if you change the grades it returns that it is not a lost. however I tried this and have found that it still works. Is there a different way this is supposed to be done? done this go against standard practices and that is why I am getting an error? Thanks for the feedback!

See the code listed below

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]
}
students= [lloyd, alice, tyler]
#print students
for student in students:
    print student["name"]
    print student["homework"]
    print student["quizzes"]
    print student["tests"]

print students[1]["name"]

def average(numbers):
    total = sum(numbers)
    avg = float(total) / len(numbers)
    return avg
    
def get_average(student):
    where = students.index(student)
    hw = students[where]["homework"]
    qz = students[where]["quizzes"]
    ts = students[where]["tests"]
    homework = average(hw)
    quizzes = average(qz)
    tests = average(ts)
    grades = (homework*.1)+(quizzes*.3)+(tests*.6)
    return grades
    
test = get_average(alice)
print test

#2

Your code works for dictionaries present in the list students.
It should work for any dictionary you pass in, even those not present in the list.
The SCT is passing in new dictionaries, and that's why you get the error that they are not in the list.
So, you need to fix this.

Hint: The where index and students list are both redundant since you already have a student dictionary as argument :wink:


#3

A simpler code with 2 more lines for checking your student score
guarangtandon geve you the right hint

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

the two lines below where added just to check the result

n=lloyd  
print get_average(n)

#4

@designcoder42719 Remember to format your code from next time as well :slightly_smiling: (tutorial)


#9

i dont know what im doing wrong towards the end

gives me the error "name 'student' is not defined"
pls help

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

def get_average(student):
homework=average(student["homework"])
quizzes=average(student["quizzes"])
tests=average(student["tests"])

homework =0.1*average(student["homework"])
quizzes =0.3*average(student["quizzes"])
tests =0.6*average(student["tests"])

print (homework*0.1)+(quizzes*0.3)+(tests