Help on functions 19!


#1



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


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


I expected the code to behave. Just kidding i wanted the function distance_from_zero to workout the absolute value of a data type as long as it is a integer or a float.


def distance_from_zero(DFZ):
    if type(DFZ) == int or float:
        return abs(DFZ)
    else:
        return 'Nope'


#2

Hi @betajumper03616 ,

The or operator takes two operands. One of the operands in the expression that you wrote is type(DFZ) == int. The other is simply, float. That might not be what you intended.


#3

i was doing so well on my own and troubleshooting my own errors until now. Haha thankyou !


#4

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