Can you explain each line?


#1

How did each line logically come about? Please explain to me in detail how each line of code came about so I can understand this better.

def is_int(x):
absolute = abs(x)
rounded = round(absolute)
return absolute - rounded == 0

I don’t see anything about True or False in the code, which is what I thought the instructions were asking for. Plus, the challenge assumes I’m supposed to remember all the built in functions from previous modules.


#2

a comparison gives true or false as result, you have a comparison here:

absolute - rounded == 0

you can break that line down into multiple lines if you want

nope, that is why documentation exist. As a developer, you need to come up with a solution


#3

What exactly is this piece of code stating by subtracting abs and rounded then == 0?


#4

the absolute value helps us deal with negative numbers (integers and float), if the absolute value minus the rounded value equals zero, it means the digit was integer or had a zero decimal value

abs(-7.4) gives the absolute distance to zero (7.4)

7.4 - round(7.4) results in .4, which will not equal zero

its perfectly possible to add function calls with different values, then inside the function to add print statement to see what each line does


#5

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