3/15 I really don't get these... Looking for a little help/motivation


#1

I don’t even have code

def is_int(x):
  if float(x) >0:
    return True
  else:
    return False

#2

So where did this code come from?


#3

This was my base code…
By “not having any code”, I meant I did not have any code that really pertained to the problem


#4

Not sure I follow your logic,

if float(x) > 0

#5

I thought float checked to see if it was a decimal or not


#6

A float can be any number, even an integer, as in 1.0. Our program should be able to identify that as an integer since it has no decimal value.

One simple check to follow up on is divisibility by unity (1).

if x % 1 == 0

When x % 1 is greater than zero, the number is not an integer.


#7

Thank you, this is what I needed


#8

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