Is_int function problems


#1

I have this function:

def is_int(x):
  
  if type(x)) == int:
    return True
  else:
    return False

But it does not work because the function should take float number such as 7.0 (decimal value is zero) as integers as well. I don’t know how to do it.


#2

Consider when the decimal component makes a difference (math operations) and use that to test whether it’s integer or not
Or, as with many other tasks, you might also consider how you would manually determine whether a number is an integer.
If you’ve done the digit sum exercise, then there’s probably also some point in time while extracting the digits where you can tell if you’re dealing with digits smaller than 1


#3

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