Python function always returns "None" when it appears as though it should return a string

def distance_from_zero(Z)

    E = "Nope"

    if type(Z) == int or float and not str:

        return abs(Z)

    elif type(Z) == str:

        return E

distance_from_zero(57)

 

I am trying to learn Python through codecademy.com. I often find it difficult to understand where I make mistakes. 

In my mind I think this should work, But every time I run it it returns "None" where I expect 57 or "Nope".

Please help me! I'm discombobulated!

 

            ~pipnina

I might be wrong here, but the if statement in the function block should probably be:

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

[...]

elif type(Z) == str:

[...]

It doesn't matter here if it's not string since it can't be a string if it's an int or float. I don't know Python well, but I'm pretty sure no computer language can compile 'x == 4 or 5' correctly. You need to explicitly say 'x == 4 or x == 5' or it will look at 5 as a condition ("is 5 true or false?"), which should produce some sort of an error.

I'm afraid It still produces "None". 

"Your function seems to fail on input True when it returned 'None' instead of 'Nope'"

I implemented your modifications.

Thanks for trying to help, though. 

The reason why it's not printing anything is because you never told it to print something. Return does not print the value. To do what you want it do, you have to use "return print(abs(Z)). What return does is associate a value to the function and ends the function, that's all. It does not print anything.

To see this easily, try running this simple function

 def test():

return("Why doesn't this work?")

test()

 It won't display anything.

edited for grammar errors :/