19.review;built in functions


#1

Example worked. But not sure why is it not returned any values on the console? Guys! any idea?

def distance_from_zero(num):

if type(num) == int:
return abs(num)
elif type(num) == float:
return abs(num)
else:
return "Nope"

distance_from_zero(10.5)


#2

There won't be a print out unless your print the return value.

print distance_from_zero(-25)

#3

Nicely done!
Worked for a string as an argument, too!

Thanks.


#4

Tried this after seeing the examples here, but keeping what i had made already, i got a pass by doing this;

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

Was necessary to use "print" ?


#5

Good question. I have that quest also. Please somebody help!


#6

Can't say for sure without a link to the exercise (so we can check) but assuming it is not asked for, we only need to print if we want to test our function.


#7

Got it! Well, it didn't ask for the print command, so i didn't use. Thanks for the answer!


#8

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