My solution for 3 / 15 is.int


#1

def is_int(x):
if x == int(x):
return True
else:
if x % 2 == 0 or x % 2 == .5:
return True
else:
return False

print is_int(-2)
print is_int(5.0)


Note from moderator: please refrain from posting code answers as doing so is against the forum guidelines. Thanks!


#2

Ok let's do this and you will see you have an issue,

is_int('a')

Does this

# ValueError: invalid literal for int() with base 10: 'a'

Now I do not blame you, but they did a terrible job asking us to define a function that determines if something is an integer.

In order to properly do this you need to use try as follows

def is_int(data):
    try:
        return int(data)
    except ValueError:
        print("You failed to enter a valid entry!")

Now this does not tell us if it is explicitly an int type, this will

def is_int(data):
    """
    This Function returns the data if it is a whole number positive/negative or zero
    """
    try:
        return int(data) if data % 1 == 0 else False
    except TypeError:
        print(False, "error")

#3

I agree with zeziba that in a real world application we’d need to sanitize input but for the purposes of this course I think it’s overkill.

You should check your function as it returns True for is_int(2.5)

The hint for this exercise is super useful and points you to solving the problem with a single line.


#5

I had some extra stuff in there on accident from my other code. I just copy and pasted it lol. It's the right code now.