I Am Having Trouble With This


#1

In the Practice Makes Perfect lesson, I have been having trouble with 3/15 and above. Please tell me some tips to help me understand this.


#2

You can test for integer using the type(n) function but it won’t work if the number is a float and also and integer eg. 8.0.

You can however user round(n) and see if there is a difference between the original number and the rounded number. If the difference is 0, then True .

def is_int(x):
  if x - round(x) == 0:
    return True
  else:
    return False

#3

Thank you! This helped a lot! I still don’t get everything else :frowning:


#4

I just used the following code. Its nice and succinct. If you have a problem with other lessons it is best to use the heading of the lesson number and title eg: is_int 3/15.

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

#5

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