Weight and see


#1

Hi there, I have no ideas what is wrong here, I read all the topics about Weight and see and my code seems to look exactly the same!

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

#2

What makes you say it's wrong? Gotta start there


#3

I get a message:
Oops, try again. get_average(alice) raised the following error: local variable 'tests' referenced before assignment
and a red light :slight_smile:


#4

Well then you would look at all the places you use test and see if there's anywhere that you are indeed using it before having defined it.
Your browser probably has a search mode that can highlight all occurrences of that symbol.


#5

ionatan, thank you for the tips.
I'm looking and it seems to me the variable tests is defined in the 2nd last line of the code? In all the previous instances I'm using it as "tests", which is a string not a variable, so shouldn't be a problem...?
In this lesson I'm definitely not using tests before defining it, is it possible that it was in one of the previous lessons...? Then, how come I had green light all the way to 'weigh'?


#6

Let's say I define bob this way:

bob = bob

What value will bob refer to afterwards?


#7

OMG! Yes! It's 'tests' instead of 'average' in the second last line! :joy: can't believe I didn't see it
thanks ionatan


#8

This code works fine

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

#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.