def toFraction(x):
d = 1
while not float(x*d).is_integer():
d += 1
return str(int(x*d)) + "/" + str(int(d))
def toFraction(x, d=1):
if float(x*d).is_integer():
return str(int(x*d)) + "/" + str(int(d))
else:
return toFraction(x, d+1)
It looks like you're new here. If you want to get involved, click one of these buttons!