Built in functions (19)- stuck



global name ‘distance_from_zero’ is not defined
File “python”, line 3
if type(x) == int or type(x) == float:
IndentationError: expected an indented block

why dosent it work?

def distance_from_zero(x):

if type(x) == int or type(x) == float:
 ab = abs(x)
 return ab
 return "Nope"


IndentationError is a pretty big hint that something is off with your indent? To place something inside the function, we need to indent it


I’m going out on a limb here and wondering if you copied/pasted text. When copying the text, it tends to ruin the formatting. Your code looks correct, just remember “if” needs to be indented; “return” needs to be indented from the “if” statement; “else” needs to be indented (in line with “if”); and “return” needs to be indented after the “else.”

So, it would be something like:

def functionName(n):
—> if condition:
------> return something
–> else:
-----> return something else


except format was used:

to make the indent show correctly.


Thanks! I was going mad over this! Copy/paste indeed screwed me over!


A post was split to a new topic: 19. review: built-in functions


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