How to solve the is_int part of pratctice makes perfect?

# Is_int

**hydeshy**#4

I could only do until here.. I dont know other functions..

```
def is_int(x):
if type(x) == int:
return True
else:
return False
```

**hydeshy**#7

**factoradic**#9

Quote from the exercise:

This means that, for this lesson, you

can'tjust test the input to see if it's of type`int`

.

You have to change the condition of `if`

. Here is a small hint:

```
6 % 1
# => 0
6 % 1
# => 0.0
6.45 % 1
# => 0.45000000000000018
7.12 % 1
# => 0.11999999999999922
```

You can also use the method proposed in the description. Simply check if given number is equal to this number rounded to integer

```
round(12)
=> 12.0
round(12.0)
=> 12.0
round(3.66)
=> 4.0
round(2.353)
=> 2.0
```

**datfatcat**#11

You don't even need to import the math module to complete this problem. The hint is a huge giveaway. Especially

`n % 1 #where n is some arbitrary number`

Your code is very, very close to perfect!

**blogcoder41425**#12

This means that, for this lesson, you can't just test the input to see if it's of type int.

```
def is_int(x):
if x == round(x):
return True
else:
return False
print is_int(7.0)
```

Sorry to whoever seen this earlier, didn't have it formatted.

**devmaster16924**#13

it doesn't work for me...

it pops out "Oops, try again. Your function fails on is_int(-2). It returns True when it should return True", which is quite weird...It returns True when it should return True...

I have been driven crazy=.=

**bayoishola20**#14

Why what @blogcoder41425 won't work for you is that you need to `import`

the `math`

module

```
import math
def is_int(x):
if x == round(x):
return True
else:
return False
is_int(7.0)
```

Hope this helps!

Please mind INDENTATION LEVELS.

**bobnzero**#17

def is_int(x):

if int(x)==x:

return True

else:

return False

no importing and it pass the test

**bayoishola20**#18

Good it did.

Well, there was use of `round`

method there and so there was need to `import`

that the `math`

module.

Thank you!

**bobnzero**#19

for me it looks liked you replyed to this

def is_int(x):

if type(x) == int:

return True

else:

return False

that the problem itself needs math model to be solved. probably just me not understand the forum format

anyways thanks for helping all of us just starting out, big props

**shaun51**#20

For my solution, I skipped importing the math module and just did some casting. by explicitly converting to an int, it should drop off any decimal.

if(abs(x) - float(abs(int(x)))) > 0:

return False

else:

return True

I guess i was not thinking about the floor function (which would have made it a bit easier in hindsight). Same principal but more than one way to go about it i suppose.

**littlejoebig**#21

This is the method I used. It passed but I hope it's correct

`def is_int(x):`

if x % 1 == 0:

return True

else:

return False

**ajaxninja29189**#22

an alternative solution that doenst use the hint (the rounding tric), but that simply checks if there a decimal sign...

def is_int(x):

charss=str(x)

if '.' in charss:

pointpos=charss.index('.')

seccar=charss[pointpos+1]

if seccar == '0':

return True

else:

return False

else:

return True

**netrunner18531**#24

hey i already passed the exercise but i don't think i have done it correctly, i have read many topic about it and found many exercise where it said to import this or that and then i found your solution,

i knew what to do, in exerciser it is written exactly what to do, i.e > If the difference between a number and that same number rounded down is greater than zero

which mean the 9.22 - 9 < 0 then it is integer

but i actually didn't knew how to do it,

thanks to you, i found the solution

def is_int(x):

----if (x-round(x) )==0 :

--------return True

----else:

--------return False