Is_int


#1



I'm stuck on is_int


My code gives the following error:

Oops, try again. Does your is_int function take exactly one argument (an integer)? Your code threw a "unsupported operand type(s) for -: 'int' and 'NoneType'" error.


I would expect it to calculate round down the number and then assign True or False.


def is_int(x):
    def round_down(x):
        z = round(x) - x
        if z > 0:
            y = x
        else:
            y = z - 1
    if x - round_down(x) >= 0:
        return False
    else:
        return True


#2

This will give either 0.0 or a number less than 0. Switch the terms around...

z = x - round(x)

This will give either 0.0 or a number greater than zero.


#3

def is_int(x):
if x-round(x)==0:
return True
else:
return False


#5

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