<In what way does your code behave incorrectly? Include ALL error messages.>
The auto-correction valide it but my prog dont works for marginal case.
<What do you expect to happen instead?>
i want my prog works for all case
if x - int(x) == 0:
print x, "is a integer"
print x, "is Not a integer"
is_int(7.00000000001) #display that is Not a integer as Well
is_int(7.000000000001) #display that is a integer but it's NOT !!!
this problem occurs because python counts using base two, we humans use base ten. This difference causes the problem, codecademy is only teaching python, we can’t do anything about this implementation in python
but this problem has been given some thought, smart people attempted to fix it, and it didn’t work.
So there isn’t much we can do. We wish there was something we could do, but the truth is, we can’t.
Representation error refers to the fact that some (most, actually) decimal fractions cannot be represented exactly as binary (base 2) fractions. This is the chief reason why Python (or Perl, C, C++, Java, Fortran, and many others) often won’t display the exact decimal number you expect:
The languages listed above, are big ones, and they face exactly the same problem.
unfortunately, this analogy can not be applied in this situation. Computers are dumb, they know two things: signal (1) or no signal (0)
this also explains the base 2 counting system:
and given this is fundamental limitation within the computer, the programming language can’t do anything about it
Worrying about this problem doesn’t help, the only possible solution would be a quantum computer, given its able to have values between 0 and 1, then you could possible implement a base 10 counting system, which might fix the issue. But quantum computers are still in development, so for now, we will have to live with the restrictions of base 2)
Under the hood, of course, we still have a binary computer. However, the module is designed to keep track of the decimal digits.
The above woks well for addition, subtraction, and multiplication, although the decimal arithmetic may be slower than binary arithmetic. However, for division there are many cases where the quotient will be inexact, for example, when the operands are prime numbers.
Python also offers a fractions module for working with numbers that can be expressed as numerators and denominators that are integers. See 9.5. fractions — Rational numbers.