Part of the whole non iterable error


Part of the whole

Oops, try again. get_class_average([alice]) resulted in an error: 'NoneType' object is not iterable

i have no idea what is wrong, or what is Nonetype

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(total)
   av = total/len(numbers)
   return av

def get_average(student):
    return 0.1 * homework + 0.3 * quizzes + 0.6 * tests
def get_letter_grade(score):
    if score > 89:
        return "A"
    elif score > 79:
        return "B"
    elif score > 69:
        return "C"
    elif score > 59:
        return "D"
        return "F"


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


NoneType is a value-type similar to int and string, it only has one instance (5 is an instance of int) which is None

None represents lack of value, for example that is what a function with no return statement will return.

If you're trying to loop (iterate) through None which is what the error message is saying can not be done, then you have likely mixed up your variables somewhere.

To find where, start by finding out where the crash happens, you can do this by calling your function same way as is mentioned in that error message and by then reading the line number in the error message that you'll get in the console if you've successfully reproduced the crash. After that you would identify what you're trying loop through there, perhaps confirm that it's None by printing it, and then looking for where it's coming from


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