19/19 Help

This is what I’ve done:

def distance_from_zero(zero):
if type(zero) == int or type(zero) == float:
return abs(zero)
else:
return “Nope”

Can anyone tell me what I did wrong and what I should have done?

1 Like

In what way is it not acting like you want? And what does does your code really look like? Mind the formatting.

1 Like

Try out the identation.

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

please help me on 5/19 Functions Calling Functions

So why can’t I also get a correct response using the following code?

def distance_from_zero(x):
    if type(x) == str:
        return "Nope"
    else:
        return abs(x)

def distance_from_zero(n):

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

Worked for me. it was about formatting. Add the required 4 spaces before if and return :smile:

This is what worked for me. Make sure the spaces in your if statement are correct or you may return an error. Good luck.

hi, can someone please tell me what i am doing wrong? this is my code:

def distance_from_zero(n):

** if type(n) == int or type(n) == float:**

** return abs()**


** else:**
** return ‘nope’**

and the error message down below is:

Ops, tente outra vez.
** It looks like you have a TypeError. Make sure your function should **
only take one input. (Or check the error message for more info.) - abs()
** takes exactly one argument (0 given)**

sorry let me rewrite that

hi, can someone please tell me what i am doing wrong? this is my code:

*def distance_from_zero(n):

if type(n) == int or type(n) == float:

    return abs()

else:
    return 'nope'*

and the error message down below is:

  • Ops, tente outra vez.
    It looks like you have a TypeError. Make sure your function should
    only take one input. (Or check the error message for more info.) - abs()
    takes exactly one argument (0 given) *

I’m just learning too, but I’m pretty sure you missed the argument in abs().
Try abs(n)