Is_int: good code, small bug, just curious


#1

def is_int(x):
  if x == int(x):
    return True
  elif (x - round(x, 1)) > 0:
    return True
  else:
    return False



No problems with my code for the paramaters of the exercise, however I did notice a little hiccup in the code, and I was curios as to why it was happening.

I was testing my code with my own choice of numbers and printing the result on the console, for some reason is_int(.0124378324) or really any random float with more than one number after the “.” will return true instead of false.

Is this due to my code having it round to the nearest decimal place?


#2

You could execute your code yourself and observe what you end up doing


#3

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