It looks like you have a NameError


Hello everyone,
My name is divya, I have started coding recently with python but I have small problem in review of built in functions. Please help me.

This is the 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.

This is the code:
def distance_from_zero(-2.2):
if type(-2.2) == int or type(-2.2) == float:
return abs(-2.2)

Welcome to our forums! Please Introduce Yourself

We cannot use literals in the parameters unless written as default,


where ___ is the default value if no argument is passed to the function. Normally, we would have a variable for a parameter.


Then work with the variable inside the function. Call it with a value...

print distance_from_zero(-2.2)


def distance_from_zero(num):
if type(num) == int or type(num) == float:
return abs(num)
print distance_from_zero(2.2)

again I got same error.
File "python", line 4
print distance_from_zero(2.2)
IndentationError: unexpected indent


This line may be indented when it should not be.


I did not understand your answer, can you please explain me clearly if possible

print distance_from_zero(2.2)

If you look at your code, the function call line above is indented when it is not supposed to be. Remove all indentation from that line.


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