I need to check if a float number has decimals or not.
This is what I've tried to do this far but it doesn't seem to work. What am i doing wrong, is there a better way?
n =[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0]
a = [1.5,2]
b = a[0]
for i in range(len(n)):
if b in n: print'yes,',b,'in',n
else: print 'no,',b,'not in',n
b = b + 0.1
Result:
no, 1.5 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
no, 1.6 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
no, 1.7 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
no, 1.8 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
no, 1.9 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
no, 2.0 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
no, 2.1 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
no, 2.2 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
no, 2.3 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
no, 2.4 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
I don't see why this line say no, 2.0 is clearly in the list:
no, 2.0 not in [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]