Practice makes perfect - is integer


#1

Hello,

Can you help me understand this tip:
‘If the difference between a number and that same number rounded is greater than zero, what does that say about that particular number?’

does it mean? e.g. 3 - 3.0 = 0 == 0 this is integer => return True; 3 - 2.9 (which is rounded 3) = 0.1 != 0 This is not integer => return False

Kind Regards,
Denisa


Python - Practice Makes Perfect - Hitting a Wall!
#2

The thing here is that I don’t know how to express the float numbers different from .0.
So far I have come up with:

def is_int(x):
  if x - x != float or x - x == 0:
      return True
  else:
    return False

This show the error: " Your function fails on is_int(-3.4). It returns True when it should return False. "

If anyone could give me a tip on this task, would be very appreciated!


#3

x - x will always give zero, how is that comparison helping?

yes, you understood that right :slight_smile:


#4

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