6. Just Weight and See


#1

I don't really know what's wrong with 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]
}

Add your function below!

def average(numbers):
total=sum(numbers)
total=float(len(numbers))
total=len(total/numbers)
return total

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

Then it shows
**

Oops, try again. get_average(alice) raised the following error: unsupported operand type(s) for /: 'float' and 'list'

**

Please help!

Thank you


#2

total= len(total/numbers) should be: total = total/len(numbers), not combined


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

this works. good luck


#4

You can try this as well

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


#5

I stepped on this post probably aiming to get some help but actually I didnt needed to read it.... Gandalf Voice "You got no power here !"


#6

Actually, for me, the continuation character isn't usefull


#7

hello mate :smile: ,
i cant see whats wrong with your code, it looks good to me, so heres my code, it worked for me

Add your function below!

def average(numbers):
total = sum(numbers)
total = float(total)
return total / len(numbers)

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return homework * 0.10 + quizzes * 0.30 + tests * 0.60


#8

hey mate, if youre declaring a variable called homework, quizzes and tests and youre defining them with average(student["homework quizzes and tests]) it makes no sense to call the function average because youre not using your variables, try it like this

return homework * 0.10 + quizzes * 0.30 + tests * 0.60

AND, by doing this

you make your code more eligible

Hope it helped


#9

Yes I was less experienced when I wrote that 3 weeks ago


#10

that's exactly what I did first but I get a make sure you defined get_average error...

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

return 0.1 * average(student["homework"]) + \
0.3 * average(student["quizzes"]) + \
0.6 * average(student["tests"])

#11

did you indent your function correctly?


#12

I didn't no...
but I fixed that and now I get an indentationError: unindent does not match any outer indentation level.

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

return 0.1 * average(student["homework"]) + \
0.3 * average(student["quizzes"]) + \
0.6 * average(student["tests"])

#13

i fixed it..
im a duber