Just weight and see Error


#1



https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/2?curriculum_id=4f89dab3d788890003000096


I'm getting the error: "Oops, try again. Make sure you have defined get_average"


Although it states that I need to have get_average defined, I have (at least I thought I had) get_average defined. Any advice? (Disregard the lack of spacing. It seems that when you copy and paste the code, it removes the spacing.)


 
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"])
        
    return homework * 0.1 + quizzes * 0.3 + tests * 0.6


#2

The exception raised will be return not in a function. This line should be indented so it returns a value from the function.


#3

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

So I indent the line, and it returns the same message: ""Oops, try again. Make sure you have defined get_average"


#4

I don't see an issue with the code, but the huge indent may be a factor in what the SCT sees. Reduce the indent to 4 space characters, not a TAB.


#5

look this, you write what`s in return wrongly.
(maybe you should)
return 0.1 * average(student["homework"]) + \
0.3 * average(student["quizzes"]) + \
0.6 * average(student["tests"])


#6

get_average should be global, not a variable in another function


#7

Just to update, issue WAS with the spacing. Seems that the code from def get_average down to return homework were spaced too far and needed to line up with def average to return.


#8

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