3. is_int


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/3?curriculum_id=4f89dab3d788890003000096


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


might be a stupid question but why is -x not an integer according to the code?(google said it's an integer)


Replace this line with your code. 
def is_int(x):
    if (abs(x)==int):
        return True
    else:
        return False


#2

Without using the built in type to test the value, can you think of another way?

if abs(x) == int

is not valid code, btw.


#4

can u explain why it's not a valid code?


#5

A number cannot equal a class, It is an instance of a class, int.

if isinstance(x, int) or type(x) == int:

We would not have to write it like that, I just did so we could see both methods of checking a value. We can check it for parent class, or we can check its data type.

But I still suggest you set this simple approach aside and think of a way to check without using either of the above comparisons. This is a good practice exercise intended for that purpose.


#7

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