/* When I tried make fraction as 1/170 and this work correctly, so the program stopped after 17cycles, but when the fraction is 1/70 this doesn’t work correctly and never stopped but should do it after 7 cycles.
That’s the code:
*/
from fractions import Fraction as Fr
number = 0
fraction = 1/70
i = 0
while number != .1:
i += 1
number = Fr(fraction * i)
print(Fr(fraction * i))
I tried using Decimal() and repr(), but the situation was exactly the same.
New contributor
Чистый обзор Всегда надзор is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.