Practice makes perfect 3/15


#1
def is_int(x):
  if abs(x) - int(abs(x)) > 0:
    return True
  else:
    return False

This is the code i am trying here, can anyone please explain why is not working


#2

if abs(x) - int(abs(x)) > 0:, do you understand what this line does?

if the value is greater then 0, it means you have a decimal value (other then 0), so False should be returned, yet you return True


#3

yeah i realised my mistake as i was working on it. thanks


#4

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