I don't understand why is_int isn't working


#1



Python 15. Practice Makes Perfect Exercise 1.3: is_int


I get the following error code after trying many different answer combinations I thought should have worked:
'Oops, try again. Your function fails on is_int(-2). It returns None when it should return True.'


Below is an example of one of the codes I thought should have worked that returns:
True
None
Then 'Oops, try again. Your function fails on is_int(-2). It returns None when it should return True.'

I added the is_int(-2) at the bottom of the code to further test the results and it returns True..
I'm pretty confused, usually I figure out what I'm doing wrong eventually.. But I'm stuck, any advice?

What am I doing wrong?


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


#2

When you have added this line

is_int(-2)

at the bottom of the code, then it means that you are calling that function and the function is returning the value True.
This line means that you are calling the function is_int with the argument(input) -2.

Previously when you have not added that line then the function was working fine but it was not getting called due to which you must be seeing none instead of True.


#3

None is the default returned by functions, so its a hint you don't return a boolean value, you only print the boolean value


#7

I still receive the same error message if I remove that last line, is_int(-2). I only added that to show that it should return True instead of none like in the error message.


#8

please post an updated version of your code


#9

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


#10

I'm sure I'm missing something, but I still cannot figure out what?


#11

the function needs to return true when x is a integer, and false when x is not a integer

currently you only print if x is a integer or not

but i already covered this problem:

combined with the error message you get:

Then 'Oops, try again. Your function fails on is_int(-2). It returns None when it should return True.'

its a pretty big hint


#12

Ha, dang, thanks for spelling that our for me.. I was getting ready to pull my hair out!


#13