PRACTICE MAKES PERFECT-is_int-3/15(Need help with verifying if a number is an integer data type)


#1


Just need assistance with finding out if a number is an integer data type. :smiley:


#2

is tests for identity, not equality. That means Python simply compares the memory address a object resides in. is basically answers the question “Do I have two names for the same object?”

so why would you use is keyword?

to check if x is of type int, you would need to use type() and see of type x equals int

furthermore, for this exercise negative integer values and decimal zero (7.0 for example) are also identified as integer, int won’t consider them integers (otherwise, this wouldn’t be a challenge)


#3

I see :thinking: but then how would u get the program to accept values such as 7.0 to return True and -3.5 to return False?


#4

that is the challenge. well, you learned several things: division operator (/), modulo operator (%) and absolute function (abs) which could help you with this


#5


Still can’t seem to do it :confused: This is what I’ve done so far and idk why my program isn’t returning True for -956.0 even though it should.


#6

line 7, you get the absolute value using abs, but don’t store the absolute value anywhere? So x is still negative


#7

so, to store it would i do x=abs(x) ?


#8

that should update x with the absolute value, yes


#9

It worked! Thanks for the help man :sweat_smile:


#10