19. Review: Built-In Functions Pls Help!


#1



I tried a lot of codes and the same :frowning:

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


Oops, try again. It looks like you have a NameError. Maybe you forgot to create a function called distance_from_zero? Check the error message for more info! - global name 'message' is not defined.

File "python", line 1
def distance_from_zero(10):
^
SyntaxError: invalid syntax


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


#2

here:

def distance_from_zero(10):

the parameter of a function has to be a valid variable name, 10 is not a valid variable name

also, here:

if type(10) == int or float:

use the function parameter, so your function can work form multiply values, not just 10, and do comparison at both sides of the or operator, you won't get away with what you are currently doing. Python will now simply see if float is true, which it is, so this condition is always true

if you need more help, post an updated version of your code


#3

3 posts were split to a new topic: 19. review built in functions


#4

@stetim94
so like this?
def distance_from_zero(num):
if type(num) == int or type(num) == float:
return abs(num)
else:
return "Nope"

but it also shows "Oops, try again. It looks like you have a NameError. Maybe you forgot to create a function called distance_from_zero? Check the error message for more info! - global name 'message' is not defined."


#5

that looks fine, try a different browser. If problems persist, post your code with markup:

so indention shows and i can run the code


#7

made it, Thx! For the help :smiley:


#8