How is Everybody Doing?


#1

What is wrong with my code?


#2

there are several problems with this code

the class_list you defined on line 54 should be named students instead, and it should be a global variable, not a local variable in get_class_average function

function calls execute functions, so they should be outside the function bodies.

You should really think about the indent you use from line 50 and onward


#3

If I use different indentation, this happens


#4

better, please copy paste your full code your code to the forum so i can run it. That is easier debugging for me.


#5
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) / float(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
    
def get_letter_grade(score):
    if score >= 90:
        return "A"
    elif score >= 80:
        return "B"
    elif score >= 70:
        return "C"
    elif score >= 60:
        return "D"
    else:
        return "F"
      
      
students = [lloyd, alice, tyler]


def get_class_average(class_list):
    results = []
    for student in class_list:
        results.append(get_average(student))
    return average(results)
  
  
print get_letter_grade(lloyd)  
print get_letter_grade(alice) 
print get_letter_grade(tyler)

print get_class_average(students)
print get_letter_grade(get_class_average(students))

#6

the purpose of the get_average function is to return the average grade of a student, because you don’t return the average grade, your get_class_average will append None (the default returned by function) to list. calling average() on a list with a bunch of None’s returns an error as you experienced

one more thing, get_letter_grade which you call here:

print get_letter_grade(lloyd)  
print get_letter_grade(alice) 
print get_letter_grade(tyler)

is to convert a number grade to letter grade, so you will first need to calculate number grade of a student get_average before passing it into get_letter_grade


#7

Adding this code inside get_average function fixed it:

avrg = homework + quizzes + tests
    return avrg

Result on the console

2017-08-08 17_54_00-Learn Python _ Codecademy

Thank you very much for the help!


#8

Your code is passing the exercise now, but its not working perfectly:

all your students score an A at the moment, but this is not right. I am afraid you class shouldn’t score such high letter grades


#9

I guess it is better now but I couldn’t understand where that “B” at the end of console came from


#10

certainly better :slight_smile: the function call on line 58 calculates the letter grade for class average, which is a B


#11

Oh, fair enough. Thank you again


#12