Function review not working-----plz help


#1

num=10
from math import *

def distance_from_zero(num):
if type(num) == int() or type(num) == float():

    return abs(num)
else:
    return("nope")

This returns {{Your function seems to fail input -10 when it returned "nope" instead of 10.

Please can anyone help i read all the other post and found no help. Also please be plane in your response as i did not understand most of the other posts explanations. Thank you for your time


#2

Hi, @djm001

Here, you are calling the int and float built in functions ...

if type(num) == int() or type(num) == float():

To compare num to the corresponding int and float types, specify int and float, without those following empty parentheses.


#3

Thank you that is a very clear answer that helps a lot.