Part Of The Whole Problem

#1

File “python”, line 48
results.append(get_average(student))
^
IndentationError: unindent does not match any outer indentation level

For it to work perfectly.

``````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)

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return 0.1 * homework + 0.3 * quizzes + \
0.6 * tests

if score >= 90.0:
return "A"
elif score >= 80.0:
return "B"
elif score >= 70.0:
return "C"
elif score >= 60.0:
return "D"
else:
return "F"

def get_class_average(class_list):
results = []
for student in class_list:
results.append(get_average(student))
return sum(results) / len(results)
``````

#2

What will we see once your code sample is formatted for posting?

``````  def get_class_average(class_list):
results = []
for student in class_list:
results.append(get_average(student))
return sum(results) / len(results)
``````

Looks like a mix of tabs and spaces in the indent.

Note that the header line is indented when it should not be. The next two lines should have four spaces of indentation (do not use tabs). The next line should have eight spaces of indentation since the line is in the code block of the for statement.

The last line should have four spaces of indentation.

Python depends upon indentation to determine block scope. It is a critical aspect of authoring Python code and not something to treat lightly. When in doubt, strip all the indents and manually replace them, line by line.

``````def get_class_average(class_list):
results = []
for student in class_list:
results.append(get_average(student))
return sum(results) / len(results)
``````

#3

Now it’s saying I didn’t define get_class_average

#4

The SCT has a limited number of tests and error messages. The actual error could be something entirely different so do not take the SCT message literally, more figuratively. Check you code from top to bottom and if needs be, redo all indentation so it is consistent throughout. Re-post your code (you can leave off the dictionaries) when you’ve given it a good going over.

#5

Fixed it. get_class_average was nestled inside get_letter_grade.

#6

You are not the first person to do that, believe it. A very common error; one we can learn from.

#7

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