Built in functions 19/19 - indented but i get an error


#1
def distance_from_zero(num):
	if type(num) == int or type(num) == float:
  	return abs(num)
  else:
  	return("Nope")
  
distance_from_zero(-5)

Gets me this error in the console:

File “python”, line 3
return abs(num)
^
IndentationError: expected an indented block


#2

That’s weird, this image actually shows my code, but when i pasted it onto the forum it doesn’t look indented as well. Does anyone here have any idea why this happens?


#3

Remove any indentation on your code and put them again using only tabs or spaces, don’t mix them.

Everything related to your code logic is fine.


#4

The Python interpreter does not take kindly to code that mixes tabs and spaces for indentation.

Different environments are free to use different amounts of space to represent tabs. As a result, when you mix tabs and spaces, the indentation might look correct in the console, and not appear the same when posted. That is the case with your code.

As @kingdarboja suggested, you need to redo all of your indentation. In the Codecademy editor, it is best to use spaces and no tabs for indentation.


#5

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