# 7/9 indentation problem

#1

So here is my 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):
total = sum(numbers)
total = float(total)
total /= len(numbers)

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

if score >= 90:
return "A"
else if score >= 80:
return "B"
else if score >= 70:
return "C"
else if score >= 60:
return "D"
else:
return "F"

``````

And I get this error:
File â€śpythonâ€ť, line 23
total = float(total)
^
IndentationError: unindent does not match any outer indentation level

Sorry this is so badly formatted, I donâ€™t know how to make my code look like code.

Thanks!

#2

There are buttons in the post editor for marking text as pre-formatted which escapes the forum formatting
As for indentation, indent by 4 spaces when entering a loop/function/similar, and de-indent by 4 spaces when exiting it. Make sure that you have no tab characters in your code.

``````'	' <- tab character, should not exist in your code
``````

#3

I see, I used tab. Wouldnâ€™t it be much easier to use tab tho?

#4

Tab character and tab key are different things though, typically editors are configured to instead insert spaces (they may also have some kind of â€śsmartâ€ť behaviour associated with tab, like re-indenting current line regardless of where the cursor is, or indenting to match above line etc â€“ this is entirely down to how you configure your editor (some will even write code for the editor to do what they want for things like this)

Codecademyâ€™s editor isnâ€™t particularly well behaved. It may be inserting tab characters, it may be mixing them, and it definitely doesnâ€™t display them the same way that python interprets them

#5

I see. Thanks for the help!

#6

Havenâ€™t solved it yet though, have we?
Note, btw, that Iâ€™m not saying that this is whatâ€™s happening. As we already established, I canâ€™t see any of this. Iâ€™m just saying itâ€™s something you should not have/do.

#7

Seems to be working fine to me. And may I ask, how long did it take you to â€śmasterâ€ť python if you did so? Thanks!

#8

The more you learn the more you know how little you know.
And different people will take very different learning routes with varying amount of efficiency, usefulness, breaks, pre-existing knowledgeâ€¦ thereâ€™s no meaningful comparison whatsoever. One learns what one can.

#9

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