Review:built-in functions - Stuck, help please!


I think my code is correct, but I am receiving this error!
Oops, try again. It looks like you have a NameError. Maybe you forgot to create a function called distance_from_zero? Check the error message for more info! - global name 'distance_from_zero' is not defined

def distance_from_zero(value):

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



Make sure the if else block of code is indented into your function.


Hello @giganinja49132
You code have two main problems.

1.return() -- In the exercise, is there mention of this thing? is it important? (I think not!)

2.This block of code should be inside function and indented by 4 spaces.

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

#4 it got executed.
Thank you!
I didn't notice the indentation and I thought we need that return() for the output


There is nothing like return() in python, return is a keyword that simply used to hand over some value to the place where the function gets called.

When function reaches it (inside function's body),it halts the execution.

for example..

def someFunction():
    return something

Also return only makes sense inside the function.


Sorry to ask this!! I am new to Python and I wanted to know..
So you mean, even though we type the return statement it doesn't print anything.
It just takes the output of the function!?


no, return does not print something when we call the function,It just hands over the value.We can actually save it in variable then print it or can directly print by passing function call to print function.
Like below example..

def someFunction():
    return 5

someFunction() #This will not print anything
print someFunction() #It will print 5

# or one thing we can do is to catch the value in a variable
# then print it

someVariable = someFunction()
print someVariable #It will print 5


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