19. Review: Built-In Functions PLEASE HELP


#1

If someone could help that would be grand, severly stuck please help.

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

Error messages = Oops, try again. Your function seems to fail on input -10 when it returned 'Nope' instead of '10'

It seems as though it should work?

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

#2

r is just a number. How can it equal a data type (float or integer)?

use type() to get the data type of r, and compare the data type of r with integer and float data type


#3

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