8/9 Cant Find What's Wrong


#1

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)/len(numbers)
    return total
    
def get_average(student):
    homework = average(student["homework"])*0.1
    quizzes = average(student["quizzes"]) * 0.3
    tests = average(student["tests"]) * 0.6
    return homework + quizzes + tests
    
def get_letter_grade(score):
    if score >=90:
        return 'A'
    if score >=80:
        return 'B'
    if score >=70:
        return 'C'
    if score >=60:
        return 'D'
    else:
        return 'F'
       
def get_class_average(students):
    results=[]
    for student in students:
        results.append(get_average(student))
        return average(results)

#2

Why do you say it's wrong? What behaviour should be different?
And what does the code really look like?


#3

That is the actual code and i keep getting an error saying that lloyd and alice are returning higher than they should be


#4

Then your code is riddled with syntax errors, most involving indentation.
Do the math manually to confirm which the result should be, and then confirm that your code does indeed produce an incorrect value. Then investigate what it does differently from your manual calculation.


#5

this is what my code actually is

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)/len(numbers)
    return total
    
def get_average(student):
    homework = average(student["homework"])*0.1
    quizzes = average(student["quizzes"]) * 0.3
    tests = average(student["tests"]) * 0.6
    return homework + quizzes + tests
    
def get_letter_grade(score):
    if score >=90:
        return 'A'
    if score >=80:
        return 'B'
    if score >=70:
        return 'C'
    if score >=60:
        return 'D'
    else:
        return 'F'
       
def get_class_average(students):
    results=[]
    for student in students:
        results.append(get_average(student))
        return average(results)

#6

sorry this was giving me crap about indents


#7

Getting somewhere, even just the realisation that it was different and insufficient to produce what you described.

My advice remains the same though!

Confirm the problem - find the right result and check if your function produces it or not.
And then investigate what it does differently.


#8

i dont know what the problem is though


#9

The error message describes it, you told me what it said.

So you would need to make sure that you can reproduce it and study what happens.

How can it be reproduced? How can you make happen what that error message describes? How do you think it came up with that conclusion?


#10

dude it's returning higher for those two but not for tyler


#11

they return 91.15 instead of 85.85 as expected


#12

Great. Then you should study where it goes wrong for one of them, not tyler, since the problem is not occuring there!

So you would call your function with that input that it fails, and now that you have reproduced the scenario where it behaves incorrectly, you have something you can study


#13

you need move you return remove "TAB" there it should be look like this :

def get_class_average(students):
    results=[]
    for student in students:
        results.append(get_average(student))
    return average(results)

#14

thank you bafelmauk!!!!


#16

it's because of indenting of "return"

it should be:

for student in students:
    results.append(get_average(student))
return average(results)

#17

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