def is_int(x): if type(x)=="int": return True for index,i in enumerate(str(x)): if i=="-": return True elif i==".": for x in str(x),range(index+1,len(x)): while(x==0): return True break else: return False
why check if the data type of x equals a string?
"int" is a string,
int is a data type
if i=="-": return True
-3.4 is not a integer, so check if the first character is a
- won't do
This is a complicated solution, are you sure you want to got this way?
you learned the modulo operator, you learned
abs(), maybe you want to go back to the drawing board?
Please help me to solve the problem:
Problem is:if we pass an values like(integers) 4,4.0,-4,-4.0 the function
returns True.. because they are true Integers
how is that a problem?
-4.0 are considered integers in this program, so it should return True?
yes sir, and i don't konw how to use the abs(), for this problem
well, that is the challenge. What does
abs() do and how might we use that to our advantage here? Or the modulo operator? You could also use
Pick whatever you feel comfortable with. How could we use any of this function, because the code you posted original in this topic, looks really complicated, or do you think it can bring you close to the solution?
please , give some ideas to solve this problem.
abs()-return the value , how far the variable from zero
so if we
x minus the absolute value of
x, we get 0 for non decimal numbers,
.0 for decimal integers and
.1 for example for
5.1, this could help us in determining if
x is a integer
This is my actual question:
An integer is just a number without a decimal part (for instance, -17, 0, and 42 are all integers, but 98.6 is not).
For the purpose of this lesson, we'll also say that a number with a decimal part that is all 0s is also an integer, such as 7.0.
This means that, for this lesson, you can't just test the input to see if it's of type int.
If the difference between a number and that same number rounded down is greater than zero, what does that say about that particular number?
Thanks for your great help, i modified the code with simple int().
Is the code is right??
that looks right