Review: Built-In Functions


#1



https://www.codecademy.com/en/courses/python-beginner-c7VZg/4/3?curriculum_id=4f89dab3d788890003000096


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)


#2

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


#3

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


#4

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


#5

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