Review: Built-In Functions


This works when the argument is a number, I don't know why it stops working with a string.

The output should be "Nope"

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

print distance_from_zero(notanumber)


notanumber is not even set to any value.
so it throws an error!


Ahh I see! Either defining it as a variable or making it into a string ("notanumber") would work. Thank you!


Yeah,as notanumber is not a python data type so python does not recognize it and throws an error!


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