Review: Built-In Functions


#1

I'm stuck. What is wrong with this code?

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

def distance_from_zero(n):
type(n)
if type(n) == int or type(n) == float:
return abs(n)
else:
return "Nope"

I get error message:

File "python", line 4
SyntaxError: 'return' outside function

Oops, try again. Your function seems to fail on input True when it returned '1' instead of 'Nope'


#2

Try this code instead : :slight_smile:

def distance_from_zero(n):
if type(n) == int or type(n) == float:
return abs(n)
else:
return "Nope"