Built in functions (19)- stuck


#1

https://www.codecademy.com/en/courses/python-beginner-c7VZg/4/3?curriculum_id=4f89dab3d788890003000096#

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
else:
 return "Nope"



#2

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


#3

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


#4

except format was used:

to make the indent show correctly.


#5

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


#6

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


#7

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