Is_int how to round a variable?


In this exercise, we want to check if x is an integer. So my idea is to first create a variable y that is equal to x rounded. Example: x=5.6 => y=5.0
But up to now, I think I haven't seen a function that does that, so how am I supposed to do that?

def is_int(x):
    #I first want to create a variable y that is x rounded
    if x-y == 0:
        return True
        return False

Can someone tell me if I am trying to do the right thing here? And if maybe I missed that function in the previous lessons...
Thanks in advance :slight_smile:


both abs() and int() have been taught at this point i think.

you can read about them in the python documentation:



Rounding would bring 5.6 to 6.0, not to 5.0. What you are thinking about is actually a floor, rather than a rounding. The floor of 5.6 is 5.0.

However, for the most relevant advice on the current exercise, see @stetim94's reply.


My bad, indeed, int() has been taught at this point!

However, I don't see how to do that exercise with abs()
any hint? I'm just curious


You're absolutely right @appylpye that's definitely not rounding. Thanks


abs was taught here, and i provided a link to the python documentation (previous answer). See if that helps, otherwise we will help you further


Thanks @stetim94
What I meant was that I managed to do the exercise with int(), but I didn't understand how abs() was useful for this exercise. So I was just curious if you had a solution to that exercise, but this time with the abs() (as you mentioned it).


it is quit useful, you can do:

if abs(x) == int(x):

you get all integer values.

the absolute value equals the integer value for negative and decimal numbers with zero, but not for decimal numbers (except for zero)


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