19/19 review built in functions


#1

Why isn't this working?

19:19 pdf.pdf (26.7 KB)


#2

Could you post your code rather than creating a pdf?


#3

def distance_from_zero(num):
return type(num)

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

print distance_from_zero(-3)


#4

@cduplantier You are asking the function to return the type of num which is unnecessayr. If you take out that bit of code:

then it should work. Otherwise use mine:

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

Let me know if you need more help after that. :slight_smile: Hope it works!


#5

Thanks! That worked!


#6

good you know :slight_smile:


#7

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