Is_int, why typeCount =type(x)?


#1

Hello!

I don’t understand why is in solution typeCount =type(x)

Please explain. Thanks!


#2

Which solution? Regardless, checking the type is probably not helpful since floats can hold integer values


#3

def is_int(x):
absoluteCount = abs(x)
typeCount =type(x)
roundCount = round(absoluteCount)
if typeCount and absoluteCount - roundCount == 0:
return True
else:
return False

it’s a codeacademy solution


#4

That’s quite possibly the worst solution I’ve ever seen to this problem, not even considering that it’s meant to serve as an example


#5

:slight_smile: well, it works
at least


#6

It should read:

def is_int(x):
    return round(x) == x

Everything else in there is… ??????

abs and type are completely irrelevant, and there’s no counting being done, so the variable names are something special indeed


#7

That’s right.

it was a bit confusing, but it’s clear now

Thanks a lot


#8

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