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]
}

# Add your function below!
def average(numbers):
		total = sum(numbers)
  	total = float(total)
  	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"
  	else if score >= 80:
    	return "B"
  	else if score >= 70:
    	return "C"
  	else if score >= 60:
    	return "D"
  	else:
    	return "F"
  
print get_letter_grade(get_average(lloyd))

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.