6. Just Weight and See


#1

Here is 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 = float(sum(numbers))
average = total / len(numbers)
return average
def get_average(x):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return (tests * .1) + (quizzes * .4) + (tests *.6)

I have literally tried copy pasting every piece of working code I can find in the forums and I always get the message "Oops, try again. get_average(alice) returned 90.4 instead of the expected 91.15" and I cannot get it to change to anything else. What am I doing wrong?


get_average(alice) returned 86.55 instead of the expected 91.15
#2

Hello, @sbruess627!
Have you checked if the quizzes are multiplied by four? Because adding the values of it (1+4+6) you get eleven, other than ten.
Try to take a look at the instructions an see what they say about it!


#3

Shoot you are correct! However I still get the error. This time it says "Oops, try again. get_average(alice) returned 85.3 instead of the expected 91.15"


#4

Make sure you're multiplying each thing (homework, tests and quizzes) by the correct value and adding them!


#5

So I double checked everything and it put me right back to where I was stuck. I did accidently have tests shown twice but here is my code now

def average(numbers):
total = float(sum(numbers))
average = total / len(numbers)
return average
def get_average(x):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return (homework * .1) + (quizzes * .3) + (tests *.6)

And here is the instructions "Multiply the 3 averages by their weights and return the sum of those three. Homework is 10%, quizzes are 30% and tests are 60%."

I really can't find my mistake. It seems like the values are off but I put them in exactly how they were listed, and if I didn't the program would've failed me a couple lessons ago


#6

Your function has an
argument named x but you're not using it at anything, instead you're using student.
Try changing that!


#7

That was the trick! Thank you so much! I really appreciate the help!


#8

No problem,Sbruess! Glad to help!


#10

i also want to ask one question : how could i print the result on console?


#11

@methodslayer01568: To print anything at the console, just use print.
But now that in Python 2.x.x, to print something you'll simply have to write "print" and you want you to be printed but in Python 3.x.x, you'll need to use parentheses and the thing you want to print will have to be inside of it.


#12

A post was split to a new topic: Please help me about the following error, tks