from fractions import Fraction
def to_frac(x):
[u, v] = [int(x), x % 1]
ans = []
i = 0
while v > 0 and i < 10 and u < 1000 :
ans.append(u)
r = 1 / v
u, v = int(r), r % 1
print(r, u, v)
i += 1
print(ans)
x = Fraction(ans[-1])
i = len(ans) - 2
while i >= 0:
x = ans[i] + Fraction(1, x)
i -= 1
return ans, x
print(to_frac(0.88888888888888888))
To embed this program on your website, copy the following code and paste it into your website's HTML: