Built in function, distance from zero


#1

I also have the same problem!

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

Error message: Oops, try again. Its function seems to fail with input -10 when it returned '13' instead of '10'


Review: Built-In Function, distance_from_zero is not defined
#2

how come you are still struggling with function parameters and arguments?

look at this code and comments:

# function with parameter num
def distance_from_zero(num):
    print num # num will contain the different values we supply at function

# function call, where we supply arguments to satisfy function parameter
print distance_from_zero(5)
print distance_from_zero(6.0)
print distance_from_zero(7.5)

run this code, see how the arguments at function call get copied into function parameter? So in the if condition, you should use num (not the fixed number 13), so your function works for all the different function calls


#3

AAAAAAAAAAAAAAAAAA
It took me a while to understand but I was able to execute the task successfully :blush: Thank you very much! Haha

And I'm sorry if I did not get it right from the start and it took me a while to figure it out. What's easy for you may not be easy for me. :wink:


#4

i think you should find an article in portugues which explains parameters and arguments


#5

2 posts were split to a new topic: Distance from zero


#7