3. is_int. I Absolutely cannot for the love of god figure out how to do this


#1


Even after an hour straight looking into the Q&A's hoping to find some good explanations i still have no idea at all on how to make this thing work!

Please Help.



#2

Please post your code, so that we can help you. :slight_smile:


#3

haha that's just the thing. Since I dont know how , i havent got anything written.
the only thing i guess i'd have written is

def is_int(x):

I ain't got anything else. i just cant figure out what to do


#4

but there are plenty of topics:

https://discuss.codecademy.com/search?q=int%20category%3A147

here is some functions you can use:

abs
int


#7

A post was split to a new topic: 3. is int


#8

Although my knowledge is still little for programming. This is how I took this lesson:
This will be step by step and may come across dumbed down in parts - however it's for best explination in my opinion.

it is mainly asking you to define a function that will check to see if a number is a interger or not [whole number].
How I personally went about this was:

first define the function -

def is_int(x) -

is_int - being the function itself
(x) - being the number that it would read from

Next it asks you to put a If statement to compare if it's True or False.
The way I went about this is, since it is asking to see if it is a interger - I checked this by comparing X to the number 1.
By doing this it will always compare it as a whole number being positive or negative.

I wrote this line as followed:

if x % 1 == 0:

x - number in function
% 1 == 0 - this states if x is divisible by 1 and there is no remainder [making it equal to 0] then run the next line.
Which the next line would be:

return true - because if it comes back as 0 remainder it means the statement was true haha.

then just finish up with else: return false.

Full code below:

def is_int(x):
if x % 1 == 0:
return True
else:
return False

print is_int(0) - This was just to call my function to test it, the number can be any number.

One of my first posts so bare with the length.


#9

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