Is_int help


#1


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

the error is "Traceback (most recent call last):
File "python", line 15, in
File "python", line 10, in is_int
TypeError: unsupported operand type(s) for &: 'bool' and 'str'"


It's supposed to tell whether a number is an integer. please help! I thought this would work.


Replace this line with your code. 
its = True

def is_int(x):
    
    decimal = False
    for it in str(x):
        print it
        if it == ".":
            decimal = True
        elif decimal == True & it < 1:
            its = False
            break
    return its
        
is_int(5.0)


#2

Given that we have determined x to be a number, it is safe to assume that it will contain only one decimal point. If we go down this road we clearly contravene the instructions, which explicitly state that 7.0 is an integer. The decimal point then, is not an indicator that we can rely upon.

Recommend take another tack.


#3

The decimal point is just to tell if the place I'm analyzing is after the decimal point. then we have the elif that says that if the place is after the decimal place and it is not a zero return False.


#4

We need to confirm that it is in fact a number before checking for the decimal point. That is adding to the work load.

def is_int(x):
    if not isinstance(x, (int, float)): return "Not a Number"
    # code

Now we know it is a number and can proceed with checking for the dot.

    if '.' in str(x):
        n = str(x)[-str(x).index('.')-1:]
        if int(n) != 0: return False
    return True

#7