b_k_li
December 7, 2015, 2:38pm
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.1homework+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
total= len(total/numbers) should be: total = total/len(numbers), not combined
kyps
December 8, 2015, 10:54pm
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
2 Likes
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)
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 !”
1 Like
Actually, for me, the continuation character isn’t usefull
hello mate ,
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
2 Likes
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
2 Likes
kyps
January 2, 2016, 12:01am
9
Yes I was less experienced when I wrote that 3 weeks ago
1 Like
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"])
kyps
January 13, 2016, 11:39pm
11
did you indent your function correctly?
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"])
h_ou20
August 20, 2020, 7:40pm
14
i wrote this an i have error:
average([3, 0])