Just Weight and See


#1

Why my code is not running? its say "Oops, try again. get_average(alice) raised the following error: float() argument must be a string or a number"

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]
}

def average(numbers):
    total = sum(numbers)
    total = float(numbers)
    total = total / len(numbers)
    return total
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = avarage(student["quizzes"])
    tests = avarage(student["tests"])
    total = 0.1 * homework + 0.3 * quizzes + 0.6 * tests
    return total

#2

quizzes = avarage(student["quizzes"])
tests = avarage(student["tests"])

Misspelled average function!


#3

ooo thankks ! so silly!


#4

You'll get another problem still...

check your average(numbers) function!

There still exists a bug!

I hope it helps!

hint**
Read the instruction again...
(lesson -- student becomes the teacher : It's Okay to be Average)


#5

i changed but it still not work

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

#6

aah just see the quizzes part ! its missing a )


#7

but i was thinking how this funcion return the weighted avarages,if we need to divide the total per the len(numbers)?


#8
  1. Average function's work : is to give average of any list of numbers.
  2. get_average tho

A. It takes name of a student.

B.uses Average function and find averages of three different section of students (i.e homework,tests,quizzes).

C. then with respect to section's weights multiplies the averages of difference sections and adds it. Thus we get a overall weighted average of student.


#9

Hello there! Following is my code, and everytime I run it, it throws this error:get_average(alice) raised the following error: list indices must be integers, not str

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]
}

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

def get_average(student):
h=average(students['homework'])
q=average(students['quizzes'])
t=average(students['tests'])
r=0.1*h+0.3*q+0.6*t
print r
return r


#10

Misspelling there...

hint**
somewhere inside your code,You have mistakenly wrote student as students.
I hope it helps :slight_smile:


#11

Hey thank you so much @greentreeme! Such an silly error. It worked after I fixed that bug.


#12

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