Review: Built In Functions - Works fine in pythontutor.com


#1

Hey everyone,

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

Can anyone see what the issue is with this code? It seems to run find in pythontutor.com when I call the function with either an int, float or a string.

Give me an "Oops, try again. Your function seems to fail on input True when it returned '1' instead of 'Nope'"

def distance_to_zero(n):
    if type(n) == int or type(n) == float:
        return abs(n)
    else:
        return 'Nope'

Thanks!


#2

Well first off, instructions 1.) says, "First, def a function called distance_from_zero," and I changed mine to distance to zero and it came back with name errors. Might not be your main problem but you will need to change that. And honestly other than that your code looks good.


#3

Bah! Why is it always something that easy? Thanks for the second set of eyes!


#4

Haha no problem! that is why we are here to help out the weary souls of coders :stuck_out_tongue:


#5

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