7. Sending a Letter-Not Printing?


#1

Link

I have gotten the check mark for passing the exercise and it isn’t throwing any errors, but Lloyd’s grade doesn’t actually print in the test box (to the right. can’t remember what it’s actually called). Am I missing something here?



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"
  print get_letter_grade(get_average(lloyd)) 



#2

Take a look at the print statement. Where is it located at?

More specifically, it’s indented. That means it’s part of the function. Instead, backspace it to have no indentation.


#3

Thanks! Indents are killing me.


#4

Remember, Python uses the indents to specify code blocks. Here on Codecademy, use 2 spaces for the 1st level, 2 more for the next, and so on.

def some_function(x):
  # 2 spaces of indentation means this code
  # belongs to this function.
  # This code only runs when this function runs.

  results = []

  if x % 2 == 0:
    # this code belongs to the `if`.
    # it only runs IF the conditional expression is true.

  # this return belongs to the function.
  return results

# notice no indentation.
print some_function(5)

Some languages have curly braces or opening and closing tags to wrap up their code blocks. Python does not. We use indentation instead.

Does that make sense?


#5

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